This is the scenario. I've just stopped a thread a have pressed the back key to return to the previous activity, only problem is I want to execute a method when this happens so I thought I could override a method using something like this:
@Override protected void onResume() {
super.onResume();
}
But this seems to run when I start the activity. I want to have this functionality but when pressing the back key to return.
Sorry if it doesn't make sense, I'm not very knowledgeable of the terminology.
Your current activity will be called with onPause() when it leaves the foreground from an input standpoint, and it will be called with onStop() when it is no longer visible.
Use startActivityforResult to start Activity B. Implement override onActivityResult(int, int, Intent) method in Activity A and setResult in ActivityB. Use startActivityforResult in Activity A to launch activity B and use @override onActivityResult(int, int, Intent) method in your activity A to get data from B Activity.
Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.
As onCreate() of an Activity is called only once, this is the point where most initialization should go: calling setContentView(int) to inflate the activity's UI, using findViewById to programmatically interact with widgets in the UI, calling managedQuery(android.
According to the official documentation, onResume()
is exactly what you want - it always gets executed when the activity comes into foreground, either together with onCreate()
and/or onStart()
or alone, depending on the current process and activity states.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With