利用am start 打开activity

近期在用am start 的时候,如果指定打开Activity的类则需要加上 [-n <COMPONENT>]

其中COMPONENT 不同于在代码中指定的类名。

举例说明:


Intent i = new Intent(Intent.ACTION_VIEW);
i.setComponent(new ComponentName("com.test", "com.test.TestActivity"));
这其中指定activity可直接写入 com.test.TestActivity


使用am start

String s = "am start -n "+new ComponentName("com.test", "com.test.TestActivity").flattenToShortString();
只有这样拼接才能正确使用。最终s打印出的值为

am start -n com.test/.TestActivity





你可能感兴趣的:(利用am start 打开activity)