3 回答

TA貢獻1909條經驗 獲得超7個贊
將此添加到onCreate,你應該很高興:
// Possible work around for market launches. See https://issuetracker.google.com/issues/36907463
// for more details. Essentially, the market launches the main activity on top of other activities.
// we never want this to happen. Instead, we check if we are the root and if not, we finish.
if (!isTaskRoot()) {
final Intent intent = getIntent();
if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(intent.getAction())) {
Log.w(LOG_TAG, "Main Activity is not the root. Finishing Main Activity instead of launching.");
finish();
return;
}
}

TA貢獻1796條經驗 獲得超7個贊
我只想解釋它失敗的原因,以及如何以編程方式重現此錯誤,以便將其合并到測試套件中:
當您通過Eclipse或Market App啟動應用程序時,它會使用意圖標志啟動:FLAG_ACTIVITY_NEW_TASK。
通過啟動器(home)啟動時,它使用標志:FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_BROUGHT_TO_FRONT | FLAG_ACTIVITY_RESET_TASK_IF_NEEDED,并使用操作“ MAIN ”和類別“ LAUNCHER ”。
如果您想在測試用例中重現這一點,請使用以下步驟:
adb shell am start -f 0x10000000 -n com.testfairy.tests.regression.taskroot/.MainActivity
然后做任何事情來進行其他活動。為了我的目的,我只是放了一個按鈕來啟動另一個活動。然后,回到啟動器(主頁):
adb shell am start -W -c android.intent.category.HOME -a android.intent.action.MAIN
并模擬通過啟動器啟動它:
adb shell am start -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -f 0x10600000 -n com.testfairy.tests.regression.taskroot/.MainActivity
如果您尚未合并isTaskRoot()解決方法,則會重現該問題。我們在自動測試中使用它來確保此錯誤不再發生。
希望這可以幫助!
- 3 回答
- 0 關注
- 846 瀏覽
添加回答
舉報