Overview
I execute the command: adb shell cmd package compile -m speed -f my-package
immediately returned Success.
Next, I determine success with the following command.
adb shell dumpsys package my-package
The relevant result is as follows.
Dexopt state:
[my-package]
path: /data/app/~~RlA_7phUWI_QeKL5Ez0VaQ==/my-package-8Q64dwzm_qioAdSVBF3J5g==/base.apk
arm64: [status=speed-profile] [reason=bg-dexopt]
odex file size: base.art: 4712Kb base.odex: 6408Kb base.vdex: 82542Kb
The above information shows that [status=speed-profile] [reason=bg-dexopt] did not work.
My cell phone information
Basic Information:
adb Version: 33.0.2-8557947
Android version: 12
Kernel version: 5.10.66
Whether to root: No
System Properties:
# Note: Only useful information is listed
$ adb shell getprop
[dalvik.vm.usejit]: [true]
[dalvik.vm.usejitprofiles]: [true]
[pm.dexopt.ab-ota]: [speed-profile]
[pm.dexopt.bg-dexopt]: [speed-profile]
[pm.dexopt.boot-after-ota]: [verify]
[pm.dexopt.cmdline]: [verify]
[pm.dexopt.first-boot]: [verify]
[pm.dexopt.first-use]: [speed-profile]
[pm.dexopt.inactive]: [verify]
[pm.dexopt.install]: [speed-profile]
[pm.dexopt.install-bulk]: [speed-profile]
[pm.dexopt.install-bulk-downgraded]: [verify]
[pm.dexopt.install-bulk-secondary]: [verify]
[pm.dexopt.install-bulk-secondary-downgraded]: [extract]
[pm.dexopt.install-fast]: [skip]
[pm.dexopt.post-boot]: [extract]
[pm.dexopt.shared]: [speed]
My Discovery Process
The following logs were obtained via logcat.
PackageManager: Skipped dexOpt for start by shell: my-package
Looking at the Android code, the compilation process returns PackageDexOptimizer.DEX_OPT_SKIPPED
In the DexOptHelper class, there is the following code.
/*package*/ boolean performDexOpt(DexoptOptions options) {
final Computer snapshot = mPm.snapshotComputer();
if (snapshot.getInstantAppPackageName(Binder.getCallingUid()) != null) {
return false;
} else if (snapshot.isInstantApp(options.getPackageName(), UserHandle.getCallingUserId())) {
return false;
}
if (options.isDexoptOnlySecondaryDex()) {
return mPm.getDexManager().dexoptSecondaryDex(options);
} else {
int dexoptStatus = performDexOptWithStatus(options);
return dexoptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
}
}
As you can see, the non-SecondaryDex case is considered successful as long as the result is not PackageDexOptimizer.DEX_OPT_FAILED.
My Questions
Question 1: Why did the adb shell cmd package compile command return Success but did not take effect?
My answer. Referring to the log message above, it was ignored and processed by the system
Question 2: I compile a random package that does not exist, but it also returns Success. e.g. adb shell cmd package compile -m speed -f not-found-package
Same answer as question 1
Question 3: Why is dexOpt not allowed to run in the shell?
Additional Information
Related codes
https://github.com/aosp-mirror/platform_frameworks_base/blob/master/services/core/java/com/android/server/pm/PackageManagerShellCommand.java#L1771
Logs
Adjust the logging level to verbose inside the developer mode.
The following logs are obtained via logcat.
PackageManager: Skipped dexOpt for start by shell: my-package
I want to debug android's so file. I use start an Activity: am start [-D] [-W] to start activitey.
the applicationg package name is com.dualboot.apps.springzen . the main activity is com.dualboot.apps.springzen.Main$Activity . i use command
'adb shell am start com.dualboot.apps.springzen/com.dualboot.springzen.Main$Actinity'
it's not exist
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.dualboot.apps.springzen/com.dualboot.springzen.Main }
Error type 3
Error: Activity class {com.dualboot.apps.springzen/com.dualboot.springzen.Main} does not exist.
how to start this activity
Since you are calling a component you need to include the component -n option tag.
Use this:
adb shell am start -n com.dualboot.apps.springzen/.MainActivity
if you actually have the $ in your class name (I doubt it) which usually refers to an inner class then you need to use:
adb shell am start -n com.dualboot.apps.springzen/.Main\$Activity
I am trying to launch this app on my emulator.. Here is my adb shell am start line
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell am start -n com.example.harvey.Sunshinea1app/com.example.harvey.Sunshinea1app.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.Sunshinea1app/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.Sunshinea1app/com.example.harvey.Sunshinea1app.MainActivity} does not exist.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
I know the warning isn't such an issue but the MainActivity does not exist part of that message is pointing to an issue that is stopping the command from being able to start the program.
I know I have something wrong in regarding the path or the name but I can't see what. I guess i'm a bit confused by what is what. No doubt i've written the path wrong somewhere but I don't know where.
Here is a dir Sunshine* /s/b
I guess it might give some info that may help to determine what that adb line should be. If you need any other info please comment letting me know.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>dir Sunshine*.* /s/b
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\Sunshinea1.iml
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\test\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\buildConfig\test\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\r\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\generated\source\r\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\androidTest\java\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\androidTest\java\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\main\java\com\example\harvey\sunshinea1app
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\main\java\com\example\harvey\sunshinea1app\sunshinea1
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
EDIT
was getting this error
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell monkey -p com.example.harvey.Sunshinea1app -c android.intent.category.LAUNCHER 1
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
** No activities found to run, monkey aborted.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
Looking at carlo's answer, i've decided to include my package name in the question, this from MainActivity.java
As for my package name
C:\>type C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\src\main\java\com\exampl
e\harvey\sunshinea1app\sunshinea1\MainActivity.java | grep package
package com.example.harvey.sunshinea1app.sunshinea1;
C:\>
So now i've revised the package line in the adb shell monkey line
C:\>adb shell monkey -p com.example.harvey.sunshinea1app.sunshinea1 -c android.intent.
category.LAUNCHER 1
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a secur
ity risk. Please fix.
Events injected: 1
## Network stats: elapsed time=85ms (0ms mobile, 0ms wifi, 85ms not connected)
the adb shell monkey line does work now..
C:\>adb devices
List of devices attached
emulator-5554 device
C:\>
But the adb shell am line isn't
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>dir MainActivity.class /s/b
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app\sunshinea1\MainActivity.class
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
attempts at adb shell am start
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell am start -n com.example.harvey.sunshinea1app/com.example.harvey.sunshinea1app.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey.sunshinea1a
pp.MainActivity} does not exist.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>adb shell am start -n com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1app/.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1
app/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1
app/.MainActivity} does not exist.
C:\Users\harvey\AndroidStudioProjects\Sunshinea1>
I checked this QnA
error "activity class does not exist" when launching android app with adb shell am start
which had the idea of checking logcat
then doing adb shell am and then -a(for what follows act=) -c(for what follows cat=) and -n(for what follows cmp=) based on the output..
02-09 18:04:05.763 1277-1288/? I/ActivityManager﹕ START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.harvey.sunshinea1app.sunshinea1/.MainActivity} from pid 1781
But it doesn't work
dir MainActivity.class /s/b
shows MainActivity.class is stored here
C:\Users\harvey\AndroidStudioProjects\Sunshinea1\app\build\intermediates\classes\debug\com\example\harvey\sunshinea1app\sunshinea1\MainActivity.class
I run the adb shell am start command, with -a -c and -n, but it doesn't find the class
C:\>adb shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n com.example.harvey.sunshinea1app.sunshinea1/.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.harvey.sunshinea1app.sunshinea1/.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app.sunshinea1/com.example.harvey.
sunshinea1app.sunshinea1.MainActivity} does not exist.
C:\>
trying the suggestion in a comment
C:\>adb shell am start -n com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1app.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1
app.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey/.sunshinea1app.MainActivity} does not exist.
C:\>
a better attempt as suggested in the comment, but still fails
C:\>adb shell am start -n com.example.harvey.sunshinea1app/.sunshinea1.MainActivity
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
Starting: Intent { cmp=com.example.harvey.sunshinea1app/.sunshinea1.MainActivity }
Error type 3
Error: Activity class {com.example.harvey.sunshinea1app/com.example.harvey.sunshinea1app.sunshinea1.MainActivity} does not exist.
C:\>
Here is a pic from devtools package manager for the sunshinea1 app that I am trying to do adb shell am start on.
You can launch the app using the following command which only needs the package name of the app:
adb shell monkey -p com.example.harvey.Sunshinea1app -c android.intent.category.LAUNCHER 1
As for why your command doesn't work, I can't tell from the information provided, but I suspect that the problem is where the MainActivity class is located in your package structure. If the MainActivity class is in com.example.harvey.sunshinea1app.sunshinea1 then you will need the following command:
adb shell am start -n com.example.harvey.sunshinea1app/.sunshinea1.MainActivity
Also ensure that the package name you are using is correct and in the correct letter casing.
Edit by barlop
Carlo points out in comment, and it works-
adb shell am start -n com.example.harvey.sunshinea1app.sunshinea1/.MainActivity
You may try doing as follows:
adb>adb shell
YOUR_DEVICE:> $ am start -n com.example.harvey.sunshinea1app.sunshinea1/.MainActivity
I am seeking a way to measure launch times of general apps in Android, and happen to know that
adb logcat -b events | grep am_activity_launch_time
might be one answer.
But I failed to find out what duration the command above shows (i.e., from what event to what event). Any help?
You can use this command
cmd0=add logcat -c
to clear the logs and then execute the below command
cmd1 = "grep am_activity_launch_time Example.txt | grep com.example.example| cut -d ',' -f4-4 > Example.csv"
The values are then saved in a csv file.
Then you can the python commands
os.system(cmd0);
os.system(cmd2);
Then use matplotlib to plot the graph from the generated csv files.
axes=plt.gca()
axes.set_xlim([1,20])
axes.set_ylim([0,4000])
plt.title("Performance Analysis ")
plt.ylabel('Time in milliseconds')
plt.xlabel('Number of itirations (DEVICE:Samsung Galaxy Note 4)')
data1=np.genfromtxt("Example.csv)"
plt.plot(data1,label="Example",linewidth=2.0,color='m')
plt.legend(bbox_to_anchor=(1,1),loc=1,borderaxespad=0.)
plt.show()
Once this is done execute this file in the python cmd.
adb logcat -b all | egrep -n --color 'Displayed *'
12461:11-26 22:43:05.316 1110 1167 I ActivityTaskManager: Displayed mobi.goldendict.android.free/mobi.goldendict.android.GoldenDict: +1s494ms
You could measure app launches time in android by this.
Is there a way to get the details of the current activity that is running via adb.
I prefer parsing results of dumpsys window windows over dumpsys activity
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
Keyguard or Recent tasks list used to not show up as Activities but you were able to see them with mCurrentFocus. I have explained why in this answer.
You can use this command,
adb shell dumpsys activity
You can find current activity name in activity stack.
Output :-
Sticky broadcasts:
* Sticky action android.intent.action.BATTERY_CHANGED:
Intent: act=android.intent.action.BATTERY_CHANGED flg=0x60000000
Bundle[{icon-small=17302169, present=true, scale=100, level=50, technology=Li-ion, status=2, voltage=0, plugged=1, health=2, temperature=0}]
* Sticky action android.net.thrott.THROTTLE_ACTION:
Intent: act=android.net.thrott.THROTTLE_ACTION
Bundle[{level=-1}]
* Sticky action android.intent.action.NETWORK_SET_TIMEZONE:
Intent: act=android.intent.action.NETWORK_SET_TIMEZONE flg=0x20000000
Bundle[mParcelledData.dataSize=68]
* Sticky action android.provider.Telephony.SPN_STRINGS_UPDATED:
Intent: act=android.provider.Telephony.SPN_STRINGS_UPDATED flg=0x20000000
Bundle[mParcelledData.dataSize=156]
* Sticky action android.net.thrott.POLL_ACTION:
Intent: act=android.net.thrott.POLL_ACTION
Bundle[{cycleRead=0, cycleStart=1349893800000, cycleEnd=1352572200000, cycleWrite=0}]
* Sticky action android.intent.action.SIM_STATE_CHANGED:
Intent: act=android.intent.action.SIM_STATE_CHANGED flg=0x20000000
Bundle[mParcelledData.dataSize=116]
* Sticky action android.intent.action.SIG_STR:
Intent: act=android.intent.action.SIG_STR flg=0x20000000
Bundle[{EvdoSnr=-1, CdmaDbm=-1, GsmBitErrorRate=-1, CdmaEcio=-1, EvdoDbm=-1, GsmSignalStrength=7, EvdoEcio=-1, isGsm=true}]
* Sticky action android.intent.action.SERVICE_STATE:
Intent: act=android.intent.action.SERVICE_STATE flg=0x20000000
Bundle[{cdmaRoamingIndicator=0, operator-numeric=310260, networkId=0, state=0, emergencyOnly=false, operator-alpha-short=Android, radioTechnology=3, manual=false, cssIndicator=false, operator-alpha-long=Android, systemId=0, roaming=false, cdmaDefaultRoamingIndicator=0}]
* Sticky action android.net.conn.CONNECTIVITY_CHANGE:
Intent: act=android.net.conn.CONNECTIVITY_CHANGE flg=0x30000000
Bundle[{networkInfo=NetworkInfo: type: mobile[UMTS], state: CONNECTED/CONNECTED, reason: simLoaded, extra: internet, roaming: false, failover: false, isAvailable: true, reason=simLoaded, extraInfo=internet}]
* Sticky action android.intent.action.NETWORK_SET_TIME:
Intent: act=android.intent.action.NETWORK_SET_TIME flg=0x20000000
Bundle[mParcelledData.dataSize=36]
* Sticky action android.media.RINGER_MODE_CHANGED:
Intent: act=android.media.RINGER_MODE_CHANGED flg=0x70000000
Bundle[{android.media.EXTRA_RINGER_MODE=2}]
* Sticky action android.intent.action.ANY_DATA_STATE:
Intent: act=android.intent.action.ANY_DATA_STATE flg=0x20000000
Bundle[{state=CONNECTED, apnType=*, iface=/dev/omap_csmi_tty1, apn=internet, reason=simLoaded}]
Activity stack:
* TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
clearOnBackground=false numActivities=2 rootWasReset=false
affinity=org.chanakyastocktipps.com
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=org.chanakyastocktipps.com/.ui.SplashScreen}
realActivity=org.chanakyastocktipps.com/.ui.SplashScreen
lastActiveTime=15107753 (inactive for 4879s)
* Hist #2: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
packageName=org.chanakyastocktipps.com processName=org.chanakyastocktipps.com
launchedFromUid=10046 app=ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
Intent { cmp=org.chanakyastocktipps.com/.ui.Profile }
frontOfTask=false task=TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
taskAffinity=org.chanakyastocktipps.com
realActivity=org.chanakyastocktipps.com/.ui.Profile
base=/data/app/org.chanakyastocktipps.com-1.apk/data/app/org.chanakyastocktipps.com-1.apk data=/data/data/org.chanakyastocktipps.com
labelRes=0x7f09000b icon=0x7f020065 theme=0x1030007
stateNotNeeded=false componentSpecified=true isHomeActivity=false
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
resultTo=HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen} resultWho=null resultCode=4
launchFailed=false haveState=false icicle=null
state=RESUMED stopped=false delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=0
fullscreen=true visible=true frozenBeforeDestroy=false thumbnailNeeded=false idle=true
waitingVisible=false nowVisible=true
* Hist #1: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
packageName=org.chanakyastocktipps.com processName=org.chanakyastocktipps.com
launchedFromUid=10046 app=ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
Intent { cmp=org.chanakyastocktipps.com/.ui.MainScreen }
frontOfTask=true task=TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
taskAffinity=org.chanakyastocktipps.com
realActivity=org.chanakyastocktipps.com/.ui.MainScreen
base=/data/app/org.chanakyastocktipps.com-1.apk/data/app/org.chanakyastocktipps.com-1.apk data=/data/data/org.chanakyastocktipps.com
labelRes=0x7f09000b icon=0x7f020065 theme=0x1030007
stateNotNeeded=false componentSpecified=true isHomeActivity=false
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
launchFailed=false haveState=true icicle=Bundle[mParcelledData.dataSize=1344]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=0
fullscreen=true visible=false frozenBeforeDestroy=false thumbnailNeeded=false idle=true
* TaskRecord{450615a0 #2 A com.android.launcher}
clearOnBackground=true numActivities=1 rootWasReset=false
affinity=com.android.launcher
intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher}
realActivity=com.android.launcher/com.android.launcher2.Launcher
lastActiveTime=12263090 (inactive for 7724s)
* Hist #0: HistoryRecord{4505d838 com.android.launcher/com.android.launcher2.Launcher}
packageName=com.android.launcher processName=com.android.launcher
launchedFromUid=0 app=ProcessRecord{45062558 129:com.android.launcher/10025}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.launcher/com.android.launcher2.Launcher }
frontOfTask=true task=TaskRecord{450615a0 #2 A com.android.launcher}
taskAffinity=com.android.launcher
realActivity=com.android.launcher/com.android.launcher2.Launcher
base=/system/app/Launcher2.apk/system/app/Launcher2.apk data=/data/data/com.android.launcher
labelRes=0x7f0c0002 icon=0x7f020044 theme=0x7f0d0000
stateNotNeeded=true componentSpecified=false isHomeActivity=true
configuration={ scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
launchFailed=false haveState=true icicle=Bundle[mParcelledData.dataSize=3608]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true persistent=false launchMode=2
fullscreen=true visible=false frozenBeforeDestroy=false thumbnailNeeded=false idle=true
Running activities (most recent first):
TaskRecord{450adb90 #22 A org.chanakyastocktipps.com}
Run #2: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
Run #1: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
TaskRecord{450615a0 #2 A com.android.launcher}
Run #0: HistoryRecord{4505d838 com.android.launcher/com.android.launcher2.Launcher}
mPausingActivity: null
mResumedActivity: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
mFocusedActivity: HistoryRecord{450d7ab0 org.chanakyastocktipps.com/.ui.Profile}
mLastPausedActivity: HistoryRecord{44f523c0 org.chanakyastocktipps.com/.ui.MainScreen}
mCurTask: 22
Running processes (most recent first):
App #13: adj=vis /F 45052120 119:com.android.inputmethod.latin/10003 (service)
com.android.inputmethod.latin.LatinIME<=ProcessRecord{44ec2698 59:system/1000}
PERS #12: adj=sys /F 44ec2698 59:system/1000 (fixed)
App #11: adj=fore /F 44fa3450 1065:org.chanakyastocktipps.com/10046 (top-activity)
App #10: adj=bak /B 44e7c4c0 299:com.svox.pico/10028 (bg-empty)
App # 9: adj=bak+1/B 450f7ef0 288:com.dreamreminder.org:feather_system_receiver/10057 (bg-empty)
App # 8: adj=bak+2/B 4503cc38 201:com.android.defcontainer/10010 (bg-empty)
App # 7: adj=home /B 45062558 129:com.android.launcher/10025 (home)
App # 6: adj=bak+3/B 450244d8 276:android.process.media/10002 (bg-empty)
App # 5: adj=bak+4/B 44f2b9b8 263:com.android.quicksearchbox/10012 (bg-empty)
App # 4: adj=bak+5/B 450beec0 257:com.android.protips/10007 (bg-empty)
App # 3: adj=bak+6/B 44ff37b8 270:com.android.music/10022 (bg-empty)
PERS # 2: adj=core /F 45056818 124:com.android.phone/1001 (fixed)
App # 1: adj=bak+7/B 45080c38 238:com.dreamreminder.org/10057 (bg-empty)
App # 0: adj=empty/B 4507d030 229:com.android.email/10030 (bg-empty)
PID mappings:
PID #59: ProcessRecord{44ec2698 59:system/1000}
PID #119: ProcessRecord{45052120 119:com.android.inputmethod.latin/10003}
PID #124: ProcessRecord{45056818 124:com.android.phone/1001}
PID #129: ProcessRecord{45062558 129:com.android.launcher/10025}
PID #201: ProcessRecord{4503cc38 201:com.android.defcontainer/10010}
PID #229: ProcessRecord{4507d030 229:com.android.email/10030}
PID #238: ProcessRecord{45080c38 238:com.dreamreminder.org/10057}
PID #257: ProcessRecord{450beec0 257:com.android.protips/10007}
PID #263: ProcessRecord{44f2b9b8 263:com.android.quicksearchbox/10012}
PID #270: ProcessRecord{44ff37b8 270:com.android.music/10022}
PID #276: ProcessRecord{450244d8 276:android.process.media/10002}
PID #288: ProcessRecord{450f7ef0 288:com.dreamreminder.org:feather_system_receiver/10057}
PID #299: ProcessRecord{44e7c4c0 299:com.svox.pico/10028}
PID #1065: ProcessRecord{44fa3450 1065:org.chanakyastocktipps.com/10046}
mHomeProcess: ProcessRecord{45062558 129:com.android.launcher/10025}
mConfiguration: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 orien=1 layout=18 uiMode=17 seq=3}
mConfigWillChange: false
mSleeping=false mShuttingDown=false
Android Q broke most of these for me. Here's a new one that seems to be working (at least on Android Q).
adb shell "dumpsys activity activities | grep mResumedActivity"
Output looks like:
mResumedActivity: ActivityRecord{7f6df99 u0 com.sample.app/.feature.SampleActivity t92}
Edit: Works on Android R for me as well
dumpsys window windows gives more detail about the current activity:
adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"
mCurrentFocus=Window{41d2c970 u0 com.android.launcher/com.android.launcher2.Launcher}
mFocusedApp=AppWindowToken{4203c170 token=Token{41b77280 ActivityRecord{41b77a28 u0 com.android.launcher/com.android.launcher2.Launcher t3}}}
However in order to find the process ID (e.g. to kill the current activity), use dumpsys activity, and grep on "top-activity":
adb shell "dumpsys activity | grep top-activity"
Proc # 0: fore F/A/T trm: 0 3074:com.android.launcher/u0a8 (top-activity)
adb shell "kill 3074"
This works for me:
adb shell dumpsys activity
And this to show current activity name:
adb shell dumpsys activity activities | grep mFocusedActivity | cut -d . -f 5 | cut -d ' ' -f 1
If you want to filter out only your app's activities currently running/paused, you can use this command:
adb shell dumpsys activity activities | grep 'Hist #' | grep 'YOUR_PACKAGE_NAME'
For example:
adb shell dumpsys activity activities | grep 'Hist #' | grep 'com.supercell.clashroyale'
The output will be something like:
* Hist #2: ActivityRecord{26ba44b u10 com.supercell.clashroyale/StartActivity t27770}
* Hist #1: ActivityRecord{2f3a0236 u10 com.supercell.clashroyale/SomeActivity t27770}
* Hist #0: ActivityRecord{20bbb4ae u10 com.supercell.clashroyale/OtherActivity t27770}
Do notice that the output shows the actual stack of activities i.e. the topmost activity is the one that is currently being displayed.
Old answers stopped working in new android versions. Now I use the following:
adb shell "dumpsys activity activities | grep ResumedActivity"
You can try this command,
adb shell dumpsys activity recents
There you can find current activity name in activity stack.
To get most recent activity name:
adb shell dumpsys activity recents | find "Recent #0"
In windows, this command works for me to show current activity name
adb shell dumpsys window windows | find "mCurrentFocus"
Output:
mCurrentFocus=Window{a43a55b u0 com.android.contacts/com.android.contacts.activities.TwelveKeyDialer}
Other solutions with "grep" command produce error in my windows pc
'grep' is not recognized as an internal or external command, operable program or batch file.
So, using "find" solve the error in my case.
Here is a solution that is easier than the command line adb solution (which does work). It is easier because it is more graphical and can be done from within Eclipse.
In Eclipse with Android device attached go to Window menu > Show View > Other ... use filter text "Windows" to pull up Android > Windows ... show this. The top item in the list is the current activity.
Another way to pull this up is by showing the "Hierarchy View" perspective, which by default will show the Windows window.
Below command can be used for finding both package and current Activity name. Found this very useful command to quickly fetch these two information about an app especially when developing tests with Appium.
adb shell dumpsys window windows | grep -E 'mCurrentFocus'
Response of this command contains both package name and current Activity. For example: in following "com.android.contacts" is the package and "com.android.contacts.activities.TwelveKeyDialer" is current Activity launched on the phone which is connected via adb.
mCurrentFocus=Window{2089af8 u0 com.android.contacts/com.android.contacts.activities.TwelveKeyDialer}
Reference: http://www.automationtestinghub.com/apppackage-and-appactivity-name/
adb shell dumpsys activity activities | grep mFocusedApp works for me.
adb shell "dumpsys activity activities | grep mResumedActivity" does not work for me for my device: Google Pixel 4 Android 12, API 32
adb shell "dumpsys activity activities | grep -E 'mCurrentFocus|mFocusedApp'"
works for me as well.
My version which works for Linux and Windows:
adb shell "dumpsys activity activities | grep mResumedActivity | cut -d "{" -f2 | cut -d ' ' -f3 | cut -d "/" -f1"