我有一個應用程序,我已經把該選項登錄Facebook。用戶登錄後,我在共享首選項中存儲布爾值,以便下次用戶打開該應用程序時,他將被定向到主屏幕而不是登錄屏幕。應用程序要求登錄如果被殺死
我注意到一件事,如果我殺了應用程序,它會在下次打開它時要求登錄。它是android應用程序的默認行爲還是可以修復的,這樣我的應用程序即使在被殺死後也能保留登錄參數?
我正在使用TinyDB來存儲和檢索SharedPreferences中的值。
這裏是我的onCreate
方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tinyDB = new TinyDB(this);
final boolean loggedIn = tinyDB.getBoolean("Login", false);
if(loggedIn) {
Intent intent = new Intent(LaunchActivity.this, HomeActivity.class);
startActivity(intent);
LaunchActivity.this.finish();
}
Fabric.with(this, new Crashlytics());
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_launch);
}
int SPLASH_TIME_OUT = 3000;
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo/company
*/
@Override
public void run() {
// This method will be executed once the timer is over
startLoginOrHome(loggedIn);
}
}, SPLASH_TIME_OUT);
}
private void startLoginOrHome(boolean loggedIn) {
if(loggedIn) {
LaunchActivity.this.finish();
} else {
Intent intent = new Intent(LaunchActivity.this, SignInActivity.class);
startActivity(intent);
LaunchActivity.this.finish();
}
}
是在'onCreate'登錄? –
@RuchirBaronia是的,我在onCreate –
檢查你得到的共享pref值的默認值是什麼 – Abx