2

I am trying to run 2 activities on 2 different processes. The purpose of doing this is that my app is displaying my product which adds homescreen icons of my subproducts. Whenever i am using the main product, i want it to be displayed on the main process while my sub product to be displayed in a different activity on another process. This is so that when exiting a subproduct, resuming my main product can be fast because its already running in the background.

Reading through this: http://developer.android.com/guide/topics/manifest/activity-element.html#proc

They state that you can separate activities into different processes using android:process attribute. Here's what i've done:

<application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true" android:process="com.mypackage.myapp">
    <activity android:name=".ProductActivity"
              android:label="@string/app_name" 
              android:configChanges="orientation|keyboardHidden">
        <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
             <category android:name="android.intent.category.DEFAULT"/>
             <category android:name="android.intent.category.BROWSABLE"/>
         </intent-filter>
    </activity>
    <activity android:name=".SubProductActivity"
              android:label="@string/app_name" 
              android:configChanges="orientation|keyboardHidden"
              android:process=":com.mypackage.myapp.newprocname">
        <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
             <category android:name="android.intent.category.DEFAULT"/>
             <category android:name="android.intent.category.BROWSABLE"/>
         </intent-filter>
    </activity>
    <activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden"> <intent-filter> </intent-filter> </activity>
</application>

However, logging the current PID, both activites are actually running on the same process...

What can be the problem?

Maverick
  • 1,458
  • 2
  • 21
  • 35

3 Answers3

3

After setting the intent of the subactivity to android.intent.category.LAUNCHER (as you correctly did), set a separate TaskAffinity string for the second activity. E.g. in the second activity line in the manifest make sure you have something similar to

<activity android:name=".SubProductActivity" android:label="SubActivity"
android:taskAffinity="com.domain.project.SubActivityName">

This tells Android to run the SubProductActivity in a separate process.

Refer also to https://stackoverflow.com/a/3270422/978329

Community
  • 1
  • 1
wiztrail
  • 3,988
  • 2
  • 19
  • 18
  • 1
    I'm only asking how can this marked as an answer? I mean taskAffinity is more related with app task ( the one holding the activities, or simply the back stack). Setting this to true should only let your component run on a seperate task, but not on a seperate process. And even I can't see any launchMode property set to singleTask for the activity. – stdout Nov 10 '15 at 14:11
2

I am trying to run 2 activities on 2 different processes.

Why?

The purpose of doing this is that my app is displaying my product which adds homescreen icons of my subproducts.

That would not seem to have anything to do with having them be in separate processes.

This is so that when exiting a subproduct, resuming my main product can be fast because its already running in the background.

It would be even faster, not to mention significantly more memory efficient, for them to be in just one process. Your other activities will be in memory anyway -- having them in some separate process does not change that.

What can be the problem?

It is possible there is a flaw in your logging. It is possible that a simpler process name (e.g., :remote) will work.

However, the simplest answer is for you to delete the android:process attribute.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

I don't know if I understood your question in the right way but...

If you launch the subproduct activity from the MainProductActivity android maintains the MainProductActivity in memory and if you exit the SubProductActivity (by the back button for example) it should be as fast as android can switch between Activities... Isn't it like what you desire?

baen
  • 616
  • 1
  • 5
  • 11