开发者

Android can i avoid onCreate() being called?

开发者 https://www.devze.com 2023-01-13 19:49 出处:网络
I have two applications App-1 & App-2. App-2 has a button which will start App-1. The need is to behave like the following:-

I have two applications App-1 & App-2. App-2 has a button which will start App-1.

The need is to behave like the following:-

  1. User launches App-1 (using launcher) & activities A, B & C are started & activity C is at the top of the activity stack.
  2. Please note that entry point of App-1 is activity A.
  3. User presses home key.
  4. User then launches the application App-2. User chooses the button in App-2 to start App-1.
  5. onClick() of the button in App-2 has the following code:-

    Intent i = new Intent(); i.setAction("com.x.y.z"); //resolves to activity A of App-1 i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK)开发者_如何学运维; i.putExtra("x", "y"); startActivity(i);

After step-4, onCreate() of activity A is called which is quite normal. But I want Android to bring the entire Activity Stack to be brought to the foreground, since App-1 is running & Android hasn't killed it.(Which is the same behavior if I had launched App-1 after step-2).

I want activity C to be shown to the user.

Kindly help me if it is possible to do this.

I have tried making activity A as singleTask & singleInstance. if i do that, only activity A is brought to the foreground which is not what i want.

the snippet of App-1's manifest looks like below:-

<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 informs Android to start a new task; the new task doesn't contain B & C, so don't expect any of them to be shown. Also, FLAG_ACTIVITY_CLEAR_TOP removes B & C, which is exactly opposite to what you want.

Try removing both flags.

0

精彩评论

暂无评论...
验证码 换一张
取 消