Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resume activity in Android

Tags:

I have an app with 3 activities.

I have the main activity. This calls the second activity, which then calls the third activity. I want return to the main activity without entering the onCreate.

This is the code for the third activity:

startActivity(new Intent(TerceraActiviry.this, Main.class)); 
like image 679
Sárzena Avatar asked Sep 13 '12 14:09

Sárzena


People also ask

How do you pause and resume activity on Android?

As your activity enters the paused state, the system calls the onPause() method on your Activity , which allows you to stop ongoing actions that should not continue while paused (such as a video) or persist any information that should be permanently saved in case the user continues to leave your app.

What are activities in Android?

An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app.

What is onResume method in Android?

onResume() is called whenever you navigate back to the activity from a call or something else. You can override the onResume method similarly as onCreate() and perform the task.


1 Answers

If your Activity is still running, this code will bring it to the front without entering onCreate

Intent openMainActivity = new Intent(TerceraActiviry.this, Main.class); openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivityIfNeeded(openMainActivity, 0); 
like image 85
ThePCWizard Avatar answered Sep 28 '22 06:09

ThePCWizard