簡體   English   中英

Android是否可以避免調用onCreate()?

[英]Android can i avoid onCreate() being called?

我有兩個應用程序App-1和App-2。 App-2有一個將啟動App-1的按鈕。

需要表現為以下行為:-

  1. 用戶啟動App-1(使用啟動器),並啟動活動A,B和C,活動C在活動堆棧的頂部。
  2. 請注意,App-1的入口點是活動A。
  3. 用戶按下主頁鍵。
  4. 然后,用戶啟動應用程序App-2。 用戶在App-2中選擇按鈕以啟動App-1。
  5. App-2中按鈕的onClick()具有以下代碼:-

    意圖i = new Intent(); i.setAction(“ com.xyz”); //解析為App-1的活動A i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra(“ x”,“ y”); startActivity(i);

步驟4之后,將調用活動A的onCreate() ,這很正常。 但是我希望Android能夠將整個Activity Stack帶到前台,因為App-1正在運行且Android並未殺死它(如果我在步驟2之后啟動了App-1,這是相同的行為)。

我希望將活動C顯示給用戶。

如果可以的話,請幫我。

我嘗試將活動A設置為singleTask和singleInstance。 如果我這樣做,只會將活動A帶到前台,這不是我想要的。

App-1清單的代碼段如下所示:-

<activity android:name=".aa.a"

         android:configChanges="orientation|keyboardHidden|locale"
         android:label="@string/app_name"
         android:theme="@android:style/Theme.NoDisplay"
         >
            <intent-filter>
             <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
           </intent-filter>
           <intent-filter>
                 <action android:name="com.x.y.z" />
                 <category android:name="android.intent.category.LAUNCHER" />
                 <category android:name="android.intent.category.DEFAULT" />
             </intent-filter>

</activity>

FLAG_ACTIVITY_NEW_TASK通知Android開始新任務; 新任務不包含B&C,因此不要指望其中的任何一個顯示。 另外,FLAG_ACTIVITY_CLEAR_TOP會刪除B和C,這與您想要的完全相反。

嘗試刪除兩個標志。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM