简体   繁体   中英

Starting Main launcher activity from another activity

my Main launcher activity (the one that has android.intent.action.MAIN as its action) is Login page.

After successful login I started HOME activity and finish() the LOGIN one to prevent users returning to that page by pressing BACK button.

When I press SIGN OUT button, I want the app to return to Login page. But I can't find a way to do it. Here's the sign out code:

//This method is in HOME activity
private void signOut(){
    Intent i = new Intent("android.intent.action.MAIN");
    startActivity(i);
    finish();
}

That code will open dialog box listing all applications in my phone for me to choose. I tried putting the package name + class name ( com.example.test.Login ) as the Intent but keep getting this error:

android.content.ActivityNotFoundException: No Activity found to handle Intent

I know I can trick this problem by using Splash screen as Main activity. But If there is another better solution, I want to know it.

Thanks

Use

Intent i = new Intent(this, LoginPage.class);
startActivity (i);
finish();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM