Log in screen on first start

柔情痞子 提交于 2019-12-02 17:51:53

问题


how would you create an activity that only runs when the application is started for the first time ever and provides the user with a screen to input a pin and "unlock" the application


First time ever meaning when the application is first installed and started for the first time. As in the FIRST EVER time it is opened.


回答1:


You can use android preferences for show login screen only for the first time.

You can set flag in preference and check it when application start.




回答2:


You can always start with something like "splash screen" activity, that will only check in database/ shared preferences if user is logged in. Then you can run login activity or not. Or in first activity you can show popup window with request of login.




回答3:


You can use sharedPreferences:

boolean firstTime = prefs.getBoolean("firstTime", true);
if(firstTime) {
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("firstTime", false);
    editor.commit();

    //do your first time "operations" here E.G read configuration, show user guide
}



回答4:


By "application starting for the first time ever" I am assuming you mean the first time an Activity appears on the display.

I usually test for the existence of a user preferences database. If it does not exist, then the application has not ever been active, and then I could prompt the user for a configuration update.

Look at the documentation for a PreferenceManager to get started.



来源:https://stackoverflow.com/questions/12577585/log-in-screen-on-first-start

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!