Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail From: "Eric Sosman" Subject: Re: Accessing a thread Message-ID: <50182C7E.55828.calajapr@time.synchro.net> X-Comment-To: Dirk Bruere at NeoPax Newsgroups: comp.lang.java.programmer In-Reply-To: <50182C7D.55822.calajapr@time.synchro.net> References: <50182C7D.55822.calajapr@time.synchro.net> X-FTN-AREA: COMP.LANG.JAVA.PROGRAMMER X-FTN-MSGID: 1:261/38 c1f2f15f X-FTN-REPLY: 1:261/38 3eac126b Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98] Lines: 78 Date: Tue, 31 Jul 2012 20:07:02 GMT NNTP-Posting-Host: 69.21.70.65 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1343765222 69.21.70.65 (Tue, 31 Jul 2012 15:07:02 CDT) NNTP-Posting-Date: Tue, 31 Jul 2012 15:07:02 CDT Organization: tds.net Xref: csiph.com comp.lang.java.programmer:16860 To: Dirk Bruere at NeoPax From: "Eric Sosman" To: Dirk Bruere at NeoPax From: "Eric Sosman" To: Dirk Bruere at NeoPax From: Eric Sosman 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 -+- BBBS/Li6 v4.10 Dada-1 + Origin: Prism bbs (1:261/38) -+- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24 -+- BBBS/Li6 v4.10 Dada-1 + Origin: Prism bbs (1:261/38) -+- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24 --- BBBS/Li6 v4.10 Dada-1 * Origin: Prism bbs (1:261/38) --- Synchronet 3.16a-Win32 NewsLink 1.98 Time Warp of the Future BBS - telnet://time.synchro.net:24