Force open of main activity

63 views Asked by At

I have an android app chat. It has to be secure so I want to force my app to open always at Main Activity. This doesn't happen when I click the history of launcher, it opens the activity shown on launcher history not the main activity. How can I force it open the Main Activity always?

android:clearTaskOnLaunch="true"

I have this on Manifest but doesn't work.

2

There are 2 answers

0
NorthernLights On

that seems right and it should work but this option is a bit buggy when you build the app directly to the device, please try to install the apk manually

0
Sergey Shustikov On

I offer you another way.

Look at the Application.ActivityLifecycleCallbacks, namely on :

When application was closed with HOME button or launch from recent task, you may have determine a boolean value that can be saved in SharedPreferences

boolean isSecure = false;

When activity paused - isSecure -> true -> save into sp.
When activity resumed\paused - read from sp -> isSecure = sp.getBoolean(...,false);