I am stuck with a project developed by someone else. Its a very big app. So for the purpose of understanding the code I want to know the flow, basically the name of the activity(the java file in the code) which is currently running in on my phone. I can put break-points in all activities, but is there any other way?
-
4run `adb shell dumpsys activity top` – pskink Jun 22 '16 at 06:27
5 Answers
You can use adb for it.
In your terminal run adb shell dumpsys activity top
.

- 14,529
- 13
- 63
- 88
-
1This is exactly what I was looking for. Super useful for debugging running activities your app launched – Max Aug 04 '21 at 03:36
Using ActivityLifecycleCallbacks, you don't need to add handling for all the activities. Do the registration once, it works for ALL activities, and that is it!
public class MyApplication extends Application implements
ActivityLifecycleCallbacks{
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onActivityStopped(Activity activity) {
Log.i("Tracking Activity Stopped", activity.getLocalClassName());
}
@Override
public void onActivityStarted(Activity activity) {
Log.i("Tracking Activity Started", activity.getLocalClassName());
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
Log.i("Tracking Activity SaveInstanceState", activity.getLocalClassName());
}
@Override
public void onActivityResumed(Activity activity) {
Log.i("Tracking Activity Resumed", activity.getLocalClassName());
}
@Override
public void onActivityPaused(Activity activity) {
Log.i("Tracking Activity Paused", activity.getLocalClassName());
}
@Override
public void onActivityDestroyed(Activity activity) {
Log.i("Tracking Activity Destroyed", activity.getLocalClassName());
}
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
Log.i("Tracking Activity Created", activity.getLocalClassName());
}
}
Note that you can identify which activity via activity.getLocalClassName().

- 15,894
- 22
- 55
- 66
-
This is not working for me. My application class extends MultiDexApplication, is it because of that? – Isj Jun 22 '16 at 10:29
-
You don't have to extends you application class this way. you can use: getApplication().registerActivityLifecycleCallbacks(mCallbacks), see also https://gist.github.com/alexjlockwood/6298122, note the snippet is only an example, you can easily adapt to other use cases!!! – David Jun 22 '16 at 13:49
Simple -
In each activity override onStart() method and print log like this -
@Override
protected void onStart() {
super.onStart();
Log.d("TAG -> ", "YOUR_ACTIVITY_NAME");
}
When activity start in your device, it will print log in logcat. Hope it will help!

- 1,359
- 1
- 17
- 23
From manifest figure out Launching activity and to find out methods and variables used.. u can use "Find Usages" ( Ctrl+G ).

- 2,752
- 26
- 27
If your application extends MultiDexApplication class here is a working solution.
In onCreate() method of your application class that extends MultiDexApplication add the following line to register the callbacks.
@Override
public void onCreate() {
super.onCreate();
registerActivityLifecycleCallbacks(new MyActivityLifecycleCallbacks());
}
Now make an inner class that implements ActivityLifecycleCallbacks as follow
private static final class MyActivityLifecycleCallbacks implements ActivityLifecycleCallbacks {
public void onActivityCreated(Activity activity, Bundle bundle) {
Log.v("Application","Created");
}
public void onActivityDestroyed(Activity activity) {
Log.v("Application","Destroyed");
}
public void onActivityPaused(Activity activity) {
Log.v("Application","Paused");
}
public void onActivityResumed(Activity activity) {
Log.v("Application","Resumed");
}
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
Log.v("Application","onActivitySaveInstanceState");
}
public void onActivityStarted(Activity activity) {
Log.v("Application","Started");
}
public void onActivityStopped(Activity activity) {
Log.v("Application","Stopped");
}
}
Now you may use activity.getLocalClassName()
in any overridden method you need.
This would be all you need. Happy Debugging :)

- 600
- 3
- 23