我有一個應用程序,從服務器的響應不同的情況下打開不同的活動。讓我有兩個活動Activity
A & Activity
B。 A或B不能同時啓動。假設A活動被稱爲啓動並在同一時間B也被稱爲啓動。如果A首先啓動,B隱藏它,並開始在視圖的頂部使A在背景中。我如何檢查A是否已從內部啓動活動B ??Android - 如何獲得Android上的最後前景活動?
到現在我曾嘗試:
ActivityManager m = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTaskInfoList = m.getRunningTasks(10);
Iterator<ActivityManager.RunningTaskInfo> itr = runningTaskInfoList.iterator();
while (itr.hasNext()) {
ActivityManager.RunningTaskInfo runningTaskInfo = (ActivityManager.RunningTaskInfo) itr.next();
int id = runningTaskInfo.id;
CharSequence desc = runningTaskInfo.description;
int numOfActivities = runningTaskInfo.numActivities;
String topActivity = runningTaskInfo.topActivity.getShortClassName();
Constants.debugLog(TAG, "checkActivityStack desc: " + desc + " numOfActivities: " + numOfActivities + " topActivity: " + topActivity);
}
========================= 另一個從堆棧
ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
int sizeStack = am.getRunningTasks(5).size();
for(int i = 0;i < sizeStack;i++){
ComponentName cn = am.getRunningTasks(2).get(i).topActivity;
Constants.debugLog(TAG, "checkActivityStack "+cn.getClassName());
}
採取全局變量定義在應用程序類,把它寫在一個活動啓動,並檢查變量b活動 – Reena
你可以發佈你的代碼,女巫打開這些活動? – Hamza
,否則您需要檢查活動管理器的運行進程 – Reena