Accessing a thread

  • Thread starter Dirk Bruere at NeoPax
  • Start date
D

Dirk Bruere at NeoPax

From: "Dirk Bruere at NeoPax" <dirk.bruere.at.neopax@1:261/38.remove-dpk-this>

From: "Dirk Bruere at NeoPax" <dirk.bruere.at.neopax@1:261/38.remove-rf4-this>

From: Dirk Bruere at NeoPax <[email protected]>

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?




--
Dirk

Full Spectrum Praxis : ZERO STATE : http://zerostate.net

-+- 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
 
E

Eric Sosman

To: Dirk Bruere at NeoPax
From: "Eric Sosman" <eric.sosman@1:261/38.remove-dpk-this>

To: Dirk Bruere at NeoPax
From: "Eric Sosman" <eric.sosman@1:261/38.remove-rf4-this>

To: Dirk Bruere at NeoPax
From: Eric Sosman <[email protected]>

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
(e-mail address removed)

-+- 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
 
D

Dirk Bruere at NeoPax

To: Eric Sosman
From: "Dirk Bruere at NeoPax" <dirk.bruere.at.neopax@1:261/38.remove-dpk-this>

To: Eric Sosman
From: Dirk Bruere at NeoPax <[email protected]>

To: Dirk Bruere at NeoPax
From: Eric Sosman<[email protected]>



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
(e-mail address removed)

--- 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

Thanks. It's obvious now!

--
Dirk

Full Spectrum Praxis : ZERO STATE : http://zerostate.net

-+- 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top