Android app restarts when opened by tapping app icon

Scenario:

I open the application by clicking the icon, do something, navigate through the activities, pause the application by clicking the "home" button.

Case 1:

If I open my application by clicking the icon again, the application will restart from the first step.

Case 2:

If I open the application from recently opened applications (in 4.0, by clicking the menu button and selecting my application), it will start from a paused state.

I want behavior 2 to always happen, I don't want my application to restart every time it opens by clicking the icon.

I compared the manifest file with other applications, and they are similar to mine, but they behave differently (for example, the 2nd case I want).

Edit:

The following message is set here: The application restarts completely at startup using the icon, click in the launch bar

but no answers: (

+7
android android-activity icons
source share
4 answers

I found him. I set the android:launchMode="singleTask" flag to my activity flag. I deleted this code.

I also added the onsaveInstance method to all the actions in my code, and now it works!

Thanks:)

+4
source share

Add this to your activity:

 if (!isTaskRoot()) { finish(); return; } super.onCreate(savedInstanceState); 
+1
source share

Try replacing the burst code with this code ..

 public class Splash extends Activity { protected boolean _active = true; protected int _splashTime = 2000; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.splash); Thread splashTread = new Thread() { @Override public void run() { try { int waited = 0; while (_active && (waited < _splashTime)) { sleep(100); if (_active) { waited += 100; } } } catch (InterruptedException e) { e.toString(); } finally { Intent intent = new Intent(getApplicationContext(), MainActivity.class); startActivity(intent); finish(); } } }; splashTread.start(); } @Override protected void onPause() { super.onPause(); } @Override public void onBackPressed() { // TODO Auto-generated method stub // super.onBackPressed(); } } 
0
source share

In your current activity, set some image that should be displayed for 2 seconds, as shown below.

 ImageView im = new ImageView(this); im.setImageResource(set your image); setContentView(im); intentMainScreen = new Intent(getApplicationContext(), MainScreen.class); Handler x = new Handler(); x.postDelayed(new splashhandler(), 2000); 

Then start your activity in the SplashHandler class (which implements runnable and starts the invocation in the run method).

It will display the Splash screen for 2 seconds and trigger another action.

0
source share

All Articles