I have a strange behavior of Activity in complicated legacy code. In LoginActivity I want to start some PromotionActivity
but just after onResume
it goes to onPause
. As this app has some ActivityUtils
in one of its numerous libraries - I used another approach: I called one default PublicActivity
and passed a fragment there. It looks like
Map<String, String> params = new HashMap<>();
params.put("fragmentName", PromotionFragment.class.getName());
ActivityUtils.showActivity(activity, PublicActivity.class, params);
And all is shown without problems. To understand why this works, I copied PublicActivity
from a library to the main folder as a PublicActivity2
and tried to launch it but failed again. I did different changes, even extended PublicActivity2
from PublicActivity
public class PublicActivity2 extends PublicActivity {}
ActivityUtils.showActivity(activity, PublicActivity2.class, params);
but again failed.
How is it possible that PublicActivity
is shown without problems but PublicActivity2
which is extended from PublicActivity
and used in the same showActivity
method - only goes to onResume
and immediately goes to onPause
?
I found the issue. As it's complicated legacy code with numerous libraries I didn't notice that there is some Application.ActivityLifecycleCallbacks
in one of them which listen lifecycle of activities and compare every launched activity with a list of permitted ones. So, I found that list, added my activity and all works fine.
I didn't find it quickly because it was passed from a library to main app as another interface which extends needed one, luckily searching through the app with a word Lifecycle
I found getApplication().registerActivityLifecycleCallbacks(new Analytics().getActivityLifecycleCallbacks())
So, for this weird situation when your activity immediately finishes after launching without any visible reason - my advice is to look for this ActivityLifecycleCallbacks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.