Thursday, April 24, 2014

Neighborhoods ...


Encounter a problem: I had a polling method, when polling in the first activity, open polling
public ScheduledExecutorService scheduler = Executors
. NewScheduledThreadPool (1);
public A a;
String s;
public Manager (String s) {

this.s = s;

}
public void aa () {
a = new A (s);
ScheduledFuture future2 = scheduler.scheduleAtFixedRate (a, 0, 5, TimeUnit.SECONDS);
}
When you switch to the second activity, the first activity to suspend polling, when switching back from the second the first time, continue to poll, ask how to achieve?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
@ Override
protected void onResume () {
/ / TODO Auto-generated method stub
super.onResume ();
if (manager! = null) {
/ / Manager.notify ();
manager.a.flag = true;
}
}
@ Override
protected void onPause () {
/ / TODO Auto-generated method stub
super.onPause ();
if (manager! = null) {
manager.a.flag = false;
/ *
try {
/ / Manager.wait ();
} Catch (InterruptedException e) {
/ / TODO Auto-generated catch block
e.printStackTrace ();
}
* /}
}
With a thread and did not realize the flag, I ask where is the problem?

No comments:

Post a Comment