Cocos2dxActivity does not start if opened through intent from another app activity

Platform - android , cocos creator version - 2.4.3
hi, I am trying to make a library of my game so that it can be integrated with other games as well. I am able to export “.aar” file of my game in another native android project but when I try to start my Game Activity( which extends Cocos2dxActivity), nothing happens, Eventually its returning through this code of OnCreate() in Cocos2dxActivity

if (!isTaskRoot()) {
// Android launched another instance of the root activity into an existing task
// so just quietly finish and go away, dropping the user back into the activity
// at the top of the stack (ie: the last state of this task)
finish();
Log.w(TAG, “[Workaround] Ignore the activity started from icon!”);
return;
}

I suppose this is for some reason and not meant to be commented so Is there any way to export our game as aar and use it with other projects ? if yes then can you please share the links of some tutorials or solutions as well? @slackmoehrle would be of great help if you can guide or tag someone who can guide me in right direction on this please.

Sure. I’ll ping engineering and get some help with this.

This is to prevent the activity from being rebuilt, it may have something to do with the launchMode of you start activity, try to modify your launchMode.

Also I am getting this warning on android studio

Duplicate content roots detected
Path [/Users/username/project/build/jsb-link/frameworks/runtime-src/proj.android-studio/src] of module [proj.android-studio.game] was removed from modules [proj.android-studio.project]

can this log have anything to do with the above issue?

thank you for your answer, it is working now , however upon launch I am getting another error

org.json.JSONException: No value for serviceClassPath
at org.json.JSONObject.get(JSONObject.java:389)
at org.json.JSONObject.getJSONArray(JSONObject.java:584)
at org.cocos2dx.javascript.SDKWrapper.loadSDKClass(Unknown Source)

Inside my AppActivity which extends Cocos2dxActivity , SDKWrapper is showing error (asking to add dependency on module ''prog.android-studio.game"), and if I add this

implementation project(path: ‘:game’)

in my app`s build.gradel. then it start giving duplicate dependencies. Till now I had tried to delete the build folder and rebuild it through cocos creator but still same issue. If I make a New Sample App then this issue is not present so I am sure I messed up something in my game. Any idea what I am missing here?

This error message can be ignored, it’s just a hint.

thank you @huanxinyin everything is working fine now, I just have 1 more query, when I launch my game aar from another app and presses home button on Android phone then I am able to see both apps in the background (my aar and parent project app). Is there any way to hide the aar and only show the parent project in background? I understand that this question is more related to Android than Cocos but I could not find anything on google so asking here.

Try to configure this optionandroid:launchMod= “singleTask” in AndroidManifest.xml

thank you @huanxinyin so much for pointing me right direction. Just 1 more huddle before our final product is live. There is 1 more game aar build with libgdx by some other developer and integrated in the same project, this aar is somehow preventing our aar from running. If I remove this libgdxs game aar them our game runs fine but If I include it then I am getting this error on launching our cocos aar , java.lang.UnsatisfiedLinkError: couldn't find "libcocos2djs.so" . Any idea about this error.
Maybe I am missing something in building our cocos aar, there are 2 aars which I give ,1) my game aar 2) libcocos2dx.aar , build structure is “jsb-default” . my game aar Manifest file includes <meta-data android:name="android.app.lib_name" android:value="cocos2djs" /> Is this the right way to give 2 aar? As far as I am concerned , any other aar should not affect my aar in anyway so if I somehow able to give 1 single aar instead of 2 aar , will that solve my problem?
Any link or guide will be very help full.

make sure the libcocos2djs.so build into you aar package, as I know, the arr’s AndroidManifest.xml will be merged. if meta-data no work. try load libcocos2djs library from java code manually .

Hi @huanxinyin indeed the issue was of libcocos2djs, another game was building a fat aar(armv7,arm64,x86,x86_64) while I was not selecting any APP ABI so mine was just armv7 which was causing the issue, however I have noticed that if just build for armv7 then my aar size is 9 mb but if I build a fat aar then size is 35mbs, I expected size difference to be around 2-3 mbs but it was 4times of original size. Is there any solution to that? As of now I have convinced the other developers to build for only armv7 aars but still incase some issue happens then I might have to give fat aar. I am using jsb-default to build the android project.

Did you run apk on debug mode? armv7 always runs normally in release mode, you can try. if you support multiple abi,the size always be fat.

Thank you @huanxinyin that helps. 1 more thing , I need to have launch mode singleTask or singleInstance for cocos to work, however if I use singleTask then I am able to see 2 apps in backgroud(on pressing home button in android and checking background apps) , 1st app is parent app from where my aar is being launched and another is or my aar. If I use singleInstance then there is only 1 app in background but I can not use finish() to go back to parent app as it closes the whole app. Is there any way to have 1 app in background and also use something like finish() to clear the resource and go back to parent activity?

hi @huanxinyin , it turns out that whatever launch mode i use, on calling finish() whole application (parent app and mine aar) is closing, Is there any way to just close my aar and go back go parent app?

@huanxinyin I tried to play around with the code and found out something, finish() is not closing the whole app , its just closing the activity from where I started AppActivity of my aar.
for example : ACTIVITY1 starts ACTIVITY2 starts COCOSACTIVITY , now if I call finish() in COCOSACTIVITY then ACTIVITY2 also get destroyed and I come back to ACTIVITY1. Any idea how to avoid activity2 from being destroyed? or any workaround to this.

Also ACTIVITY1 get recreated in this case rather than resume, ie. its onCreate method get called, expected result is its onResume should get called.

I am stuck at this thing for 2 days and after everything I found some exception during finishing of app , here are the logs

09-30 23:14:46.260 32059 32094 D JniHelper: JniHelper::getJavaVM(), pthread_self() = -570971856

09-30 23:14:46.277 4983 4983 I StatusBarIconController: appTransitionPending
09-30 23:14:46.304 1638 5411 I ActivityManager_Thumbnails: Setting thumbnail of ActivityRecord{67d958e u0 com.example.rummytest/org.cocos2dx.javascript.AppActivity t816 f} to android.graphics.Bitmap@7a2a26d
09-30 23:14:46.306 32059 32059 D Cocos2dxActivity: onPause()
09-30 23:14:46.310 32059 32119 E AbstractTracker: Can’t create handler inside thread that has not called Looper.prepare()
09-30 23:14:46.311 32059 32119 D AppTracker: App Event: stop
09-30 23:14:46.312 4983 4983 I StatusBarIconController: appTransitionPending
09-30 23:14:46.333 32059 32120 E AbstractTracker: Can’t create handler inside thread that has not called Looper.prepare()
09-30 23:14:46.333 32059 32120 D AppTracker: App Event: start

09-30 23:14:46.370 356 356 W auditd : type=1400 "Binder_6"“socket:[3018984]”“sockfs”
09-30 23:14:46.371 356 356 W auditd : type=1400 "Binder_6"“socket:[3018984]”“sockfs”
09-30 23:14:46.370 5273 5273 I GoogleInputMethod: onFinishInput() : Dummy InputConnection bound
09-30 23:14:46.371 5273 5273 I GoogleInputMethod: onStartInput() : Dummy InputConnection bound

09-30 23:14:46.419 4983 4983 I StatusBarIconController: animateIconTint:0.0 mDarkIntensity:0.0
09-30 23:14:46.422 4983 4983 D BarBackgroundDrawable: BarTransitions: draw: mode=MODE_TRANSPARENT, targetColor=0x0
09-30 23:14:46.428 4983 4983 I StatusBarIconController: appTransitionStarting
09-30 23:14:46.431 32059 32059 D Cocos2dxActivity: onWindowFocusChanged() hasFocus=false
09-30 23:14:46.619 1638 1669 I art : Background partial concurrent mark sweep GC freed 11538(648KB) AllocSpace objects, 5(100KB) LOS objects, 25% free, 46MB/62MB, paused 3.061ms total 323.439ms
09-30 23:14:47.133 32059 32059 D Cocos2dxActivity: Cocos2dxActivity onDestroy: org.cocos2dx.javascript.AppActivity@bbfa861, mGLSurfaceVieworg.cocos2dx.lib.Cocos2dxGLSurfaceView{26bcf64 VFE… .F…I. 0,0-1920,1080}
09-30 23:14:47.133 32059 32059 I Process : Sending signal. PID: 32059 SIG: 9
09-30 23:14:47.186 1638 5415 D GraphicsStats: Buffer count: 4
09-30 23:14:47.187 1638 6039 I ActivityManager: Process com.example.rummytest (pid 32059) has died
09-30 23:14:47.187 1638 6039 D ActivityManager: cleanUpApplicationRecord – 32059
09-30 23:14:47.187 1638 5411 I WindowState: WIN DEATH: Window{6fc8fcf u0 com.example.rummytest/com.example.rummytest.MainActivity2}
09-30 23:14:47.187 1638 2057 V ActivityManager: killProcessGroupAsync took 0 ms for PID 32059 on thread 14
09-30 23:14:47.191 1638 5499 I WindowState: WIN DEATH: Window{e4e4742 u0 com.example.rummytest/com.example.rummytest.MainActivity3}
09-30 23:14:47.195 1638 5360 I WindowState: WIN DEATH: Window{9c2404a u0 com.example.rummytest/org.cocos2dx.javascript.AppActivity}
09-30 23:14:47.195 1638 5360 W WindowManager: Force-removing child win Window{b934ffa u0 SurfaceView} from container Window{9c2404a u0 com.example.rummytest/org.cocos2dx.javascript.AppActivity}
09-30 23:14:47.206 1638 5361 W WindowManager: Failed looking up window
09-30 23:14:47.206 1638 5361 W WindowManager: java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@a881bbb does not exist
09-30 23:14:47.206 1638 5361 W WindowManager: at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8885)
09-30 23:14:47.206 1638 5361 W WindowManager: at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8876)
09-30 23:14:47.206 1638 5361 W WindowManager: at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:1216)
09-30 23:14:47.206 1638 5361 W WindowManager: at android.os.BinderProxy.sendDeathNotice(Binder.java:591)
09-30 23:14:47.206 1638 5361 I WindowState: WIN DEATH: null
09-30 23:14:47.206 1638 6039 W ActivityManager: Force removing ActivityRecord{7c11bf4 u0 com.example.rummytest/.MainActivity3 t815}: app died, no saved state
09-30 23:14:47.222 32121 32121 I art : Late-enabling -Xcheck:jni
09-30 23:14:47.223 1638 6039 V BoostFramework: BoostFramework() : mPerf = com.qualcomm.qti.Performance@57369ab
09-30 23:14:47.223 1638 6039 I ActivityManager: Start proc 32121:com.example.rummytest/u0a1515 for activity com.example.rummytest/.MainActivity2
09-30 23:14:47.248 4983 4983 I StatusBarIconController: appTransitionPending

09-30 23:14:47.328 4983 4983 D SystemServicesProxy: exclude com.android.packageinstaller
09-30 23:14:47.328 4983 4983 D SystemServicesProxy: exclude android
09-30 23:14:47.328 4983 4983 D SystemServicesProxy: add 2 Task
09-30 23:14:47.329 4983 4983 D RecentsTaskLoadPlan: preloadPlan, 2
09-30 23:14:47.347 32121 32121 W art : Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
09-30 23:14:47.356 32121 32121 I viewtest: onCreate MainActivity2
09-30 23:14:47.580 32121 32121 I viewtest: view created second fragment second activity
09-30 23:14:47.620 32121 32134 E AbstractTracker: Can’t create handler inside thread that has not called Looper.prepare()
09-30 23:14:47.620 32121 32134 D AppTracker: App Event: start
09-30 23:14:47.626 356 356 W auditd : type=1400 "Binder_1"“socket:[3019062]”“sockfs”
09-30 23:14:47.626 356 356 W auditd : type=1400 "Binder_1"“socket:[3019062]”“sockfs”
09-30 23:14:47.630 356 356 W auditd : type=1400 "Binder_1"“socket:[3019064]”“sockfs”
09-30 23:14:47.630 32121 32135 D OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

09-30 23:14:47.817 1638 2369 I ActivityManager: Displayed com.example.rummytest/.MainActivity2: +610ms
09-30 23:14:47.828 1638 5359 W InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 32059 uid 11515

09-30 23:14:47.195 1638 5360 W WindowManager: Force-removing child win Window{b934ffa u0 SurfaceView} from container Window{9c2404a u0 com.example.rummytest/org.cocos2dx.javascript.AppActivity} 09-30 23:14:47.206 1638 5361 W WindowManager: Failed looking up window 09-30 23:14:47.206 1638 5361 W WindowManager: java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@a881bbb does not exist
can this be an issue here ?

@huanxinyin @slackmoehrle I am getting the above mentioned issue even in an empty project as well, so I am hoping its solution should be simple. Can you guys please point me in some direction as all our efforts will be wasted if I could not solve this. If required I can share that sample project as well for better understanding. I only require that If user presses back button in my aar and I call finish() in my aar, parent apps previous activities in stack gets resumed rather than recreated. Right now their onCreate` method get called which is not good for user experience.

Engineering will look at this when they return from holiday.

This problem is not a problem caused by the engine, is the use of Android level problems, there is no more information to help you, it is recommended to go to the Android application-related development forum information.