Avoid Splash Screen to launch when user open app from recent screen

364 Views Asked by At

I wanna know how I can avoid splash screen to launch when my app is in recents.

I want the app to open the activity where user was in it before when he/she clicks back button of device and opens app from recent screen.

This is a splash screen activity :

public class MainActivity extends AppCompatActivity {
//variables
    private static int SPLASH_SCREEN = 1000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);



        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(MainActivity.this , Main_Page.class);
                startActivity(intent);
                finish();
            }
        },SPLASH_SCREEN);


    }


2

There are 2 best solutions below

2
On

In the manifest, specify for the activity:

android:noHistory="true"
0
On

I found the solution to my problem.

This happens because when I click back button of device, according to

activity lifecycle , ondestroyview() will be called. so when

I returned from recents screen , app started again.

what I've done is that in the next activity which appears after Splash

Screen , I used onBackPressed like this :


 @Override
    public void onBackPressed() {
             moveTaskToBack(true);
         
    }