Saturday, January 25, 2014
BroadcastReceiver how to start multiple instances of Activity
public class SmsReceiver extends BroadcastReceiver {
final String SMS_RECEIVED_ACTION = "android.provider.Telephony.SMS_RECEIVED";
@ Override
public void onReceive (Context context, Intent intent) {
if (intent.getAction (). equals (SMS_RECEIVED_ACTION)) {
Intent newIntent = new Intent (context, MyActivity.class); newIntent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity (newIntent);
}
}
}
}
The above code when you receive a new message automatically start MyActivity. The question now is: After receiving a text message starting MyActivity, if MyActivity not closed, then the message will no longer receive the follow-up to start a new instance of the MyActivity. How to ask to solve this problem?
Reply:
Set about startup mode, singleTask
Reply:
Intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Like this
Reply:
Intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
Tried it feasible
Set about startup mode, singleTask
Tried it and found that upon receipt of the second message, the first MyActivity performed onPause () method, while the second MyActivity only implemented onResume () method does not execute onCreate () and onStart () method
Reply:
In onPause method finish off the next open new
Reply:
Reply:
I can not directly in front of the Activity to finish off, because the user may return to view prior messages
Reply:
Intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
Can.
Proposed landlord look intent flag parameter data
singtask new task singtop singleinstance
Reply:
If MyActivity not closed, then it will not execute onCreate event, and will run
onNewIntent events, create the landlord can write about, like listening onDestroy, onResume, onStop same.
public void onNewIntent (Intent intent) {
Log.e (TAG, "onNewIntent");
super.onNewIntent (intent);
}
Reply:
Intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP)
So there is still a problem, and that is after 2 SMS Activity executing the onResum (), will execute the first one SMS Activity in onDestroy (). Such messages after closing the first two, you can not see the first one text messages.
How can we close the first N of SMS Activity after, but also see the previous N-1 SMS in Activity?
Reply:
Intent.FLAG_ACTIVITY_CLEAR_TOP no need to clear the top of the stack, right? ?
Reply:
The landlord, not solve ah? Solving ~ ~ ~ ~ Solution for a few days, but also not the best solution.
Reply:
intent.setFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags (Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment