Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16612
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Eric Sosman <esosman@ieee-dot-org.invalid> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Accessing a thread |
| Date | Mon, 30 Jul 2012 09:10:33 -0400 |
| Organization | A noiseless patient Spider |
| Lines | 54 |
| Message-ID | <jv614i$uib$1@dont-email.me> (permalink) |
| References | <a7n3u2FhvtU2@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Mon, 30 Jul 2012 13:10:43 +0000 (UTC) |
| Injection-Info | mx04.eternal-september.org; posting-host="d3779b2c4a3397eb5709eec94bad057a"; logging-data="31307"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4+MaHAWL3yLNCUA29tErO" |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 |
| In-Reply-To | <a7n3u2FhvtU2@mid.individual.net> |
| Cancel-Lock | sha1:IS2bdUwpsX6bVgRoEZCARElzHPI= |
| Xref | csiph.com comp.lang.java.programmer:16612 |
Show key headers only | View raw
On 7/30/2012 5:54 AM, Dirk Bruere at NeoPax wrote:
> File1
>
> public class controller extends Activity {
>
>
> /** Called when the activity is first created. */
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.main);
>
> final LanSendThread lanSendThread = new LanSendThread();
> lanSendThread.start();
> ...}
>
> __________
>
> File2
>
> public class LanSendThread extends Thread{
> public static Handler lanSendHandler;
>
> @Override
> public void run(){
> Looper.prepare();
>
> lanSendHandler = new Handler() {
> //stuff}
>
> ___________
>
> How do I access the thread lanSendThread from another class in another
> file?
The same way you'd access it if it were an ArrayList or
a JButton or a File: You save the reference somewhere and dish
it out to interested parties. There must be two or three jillion
ways to do this; a few of them are
- Make `lanSendThread' a public member of the controller
class (poor choice of name, by the way). You may or may
not want to make that member `final'.
- Make `lanSendThread' a private member of the controller
class, and write a public getThread() method to return it.
- Stash the value of `lanSendThread' in a Map or other data
structure, and "publicize" the data structure and/or
accessors for it.
--
Eric Sosman
esosman@ieee-dot-org.invalid
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Accessing a thread Dirk Bruere at NeoPax <dirk.bruere@gmail.com> - 2012-07-30 10:54 +0100 Re: Accessing a thread Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-07-30 09:10 -0400 Re: Accessing a thread Roedy Green <see_website@mindprod.com.invalid> - 2012-07-30 19:34 -0700
csiph-web