[英]Android onActivityResult not called
情況
我在StartActivity
onCreate中開始2個活動。 UnlockActivity
我的MainActivity
和UnlockActivity
。
private final static int REQUEST_UNLOCK = 13245;
[...]
Intent mainIntent = new Intent(this, MainActivity.class);
startActivity(mainIntent);
Intent intent = new Intent(this, UnlockActivity.class);
startActivityForResult(intent, REQUEST_UNLOCK);
UnlockActivity提示用戶輸入密碼,僅在輸入正確密碼后關閉。 我的MainActivity包含應用程序的其余部分。
對我來說重要的是,活動啟動順序保持不變。 當UnlockActivity
啟動時, MainActivity
會加載。 另外, UnlockActivity
用於確認整個應用范圍內的用戶操作,還可以顯示在后台計時器上。
這是他們的AndroidManifest條目:
<activity android:name=".main.MainActivity" android:theme="@style/AppTheme" />
<activity android:name=".unlock.UnlockActivity" android:launchMode="singleTop" android:theme="@style/AppTheme" />
問題
無論應用程序是否已解鎖一次,我都需要在SharedPrefs中設置一個標志。 為此,我嘗試使用onActivityResult
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_UNLOCK && resultCode == Activity.RESULT_OK) {
// i set the flag to true here
}
}
}
但是由於某種原因,永遠不會調用onActivityResult
。 為什么?
檢查兩件事。
setResult(RESULT_OK, intent)
和finish();
在UnlockActivity中?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.