2010-02-19 17 views
3

我目前正在使用一個使用多個Activity來顯示每個屏幕的應用程序來運行自動化測試。Android Instrumentaion:我如何返回之前啓動的Activity?

有沒有辦法在運行Instrumentation測試時返回之前啓動的Activity?目前,當我使用sendKeyDownUpSync(KeyEvent.KEYCODE_BACK)時,這迫使我的測試退出,而不是回到以前的活動。

任何幫助,這是非常感謝。

回答

6

你可以試試呼籲要關閉活動的finish()方法。

1

很酷。 finish()工作得很好:)除非,當然,Android Runtime不會殺死以前的活動來釋放資源。

1

您也可以使用方法來做到這一點。 Thia不是推薦的做法,但下面是可以爲你使用的代碼。

public void launchActivityCurrent() { 
     Intent intent = new Intent(Intent.ACTION_MAIN); 
     intent.addCategory(Intent.CATEGORY_LAUNCHER); 
     System.out.println("Inside Launch Activity current"); 
         intent.setClassName("YourpackageName","Activity you want to launch"); 
         For ex: 
     intent.setClassName("com.android.mms","com.android.mms.ui.ConversationList"); 
     Context c = currentContext(); 
     c.startActivity(intent); 
    } 

我使用robotium,我不再調用儀器,所以我用這種方式在應用程序活動中啓動。 我希望這對你也很有用。

相關問題