Issue
I try to use onStart() or onResume() at first. However, there are two drawbacks to use them.
1, If I start another activity and dismiss it later, as follow. (Kind of like modal present a new viewcontroller and then dismiss it)
private void dismiss() {
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.setClass(this, MainActivity.class);
startActivity(intent);
finish();
}
onResume() will still be called
2, I can't reuse the same login in other activity.
Therefore, I wonder if there is an method in Android is exactly the same as - (void)applicationWillResignActive:(UIApplication *)application in Android
Solution
If you bring the MainActivity
to the front using your dismiss()
code, you can detect this in MainActivity.onNewIntent()
like this:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if ((intent & Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) != 0) {
// I've been brought to the FRONT by another activity
}
}
Does this help? I'm not 100% sure I understand what you want.
Answered By - David Wasser
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.