如果我的问题看起来重复,我深表歉意。但是,我仍然找不到任何可以帮助我的答案或教程。
我想开发一个应用程序,用户安装应用程序后需要登录一次。因此,如果用户想使用该应用程序,则无需再次登录。用户的数据需要存储在 sqlite 中才能登录应用程序。
是否有任何教程或任何可以帮助我的东西。
提前致谢。
最佳答案
第 1 步:创建一个 Splash Activity
并将其用作应用程序的入口点。 NoDisplay 使其对用户不可见。它不需要布局
<activity
android:name="your.package.name.Splash"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoDisplay" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
第 2 步:在该 Activity
中检查用户是否已登录:
public class Splash extends Activity {
private SharedPreferences prefs;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
if (!prefs.getBoolean("UserLoggedIn", false)) {
startActivity(new Intent(this, UserLoginActivity.class));
finish();
} else {
startActivity(new Intent(this, YourActivity.class));
finish();
}
}
}
在用于用户登录的 Activity
中,创建一个 boolean
值并在登录完成后将其设置为 true(示例):
..........
prefs = PreferenceManager
.getDefaultSharedPreferences(UserLoginActivity.this);
Editor editor = prefs.edit();
editor.putBoolean("UserLoggedIn", true);
editor.commit();
startActivity(new Intent(UserLoginActivity.this,
NextActivity.class));
here是使用 SharedPreferences
关于java - 安装 Android 应用程序后首次使用时创建一次登录页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15599232/