Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any method that runs when returning to activity?

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.

like image 616
aelsheikh Avatar asked Dec 06 '11 23:12

aelsheikh


People also ask

Which method is used to call another activity when we expect to get something back?

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.

How do you return data to the starting activity?

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.

How do I get my old Android activity back?

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.

Why do we need to call setContentView () in onCreate () of activity class?

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.


1 Answers

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.

like image 50
olex Avatar answered Oct 16 '22 07:10

olex