简体   繁体   中英

Android - How to change the launch activity?

How can I set an Activity that will be the Launch Activity just one time ( when the user sign up )? eg I have a Settings Activity and a NewsFeed Activity. The first time I want to lanch the app with the Settings Activity and, after the user fill the options, he goes to the NewsFeed Activity. The second time, after the settings filled, I want to launch the app with NewsFeed Activity.

I google it but could not find any detailed explanation or tutorial.

Its very simple.

You can use preferences to store if this first time then show Settings Activity else always show NewsFeed Activity.

Below is the sample code to use Preferences

SharedPreferences prefs = this.getSharedPreferences("MyAppPrefs", MODE_WORLD_0);
boolean settingsFilled = prefs.getBoolean("SettingsFilled", false);

if(!settingsFilled)
{
    //SHOW SETTINGS ACTIVITY

    SharedPreferences prefs = this.getSharedPreferences("MyAppPrefs", 0);
    Editor editor = prefs.edit();
    editor.putBoolean("SettingsFilled", true);
    editor.commit();
}

Use the above code in your NewsFeed Activity.

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