How can I start a new android activity using class name in a string?

前端 未结 4 1458
情深已故
情深已故 2020-11-28 06:21

I\'m having a problem with an android application that I\'m working on.

My application has several sections and the next screen that loads is based on a string. So,

4条回答
  •  攒了一身酷
    2020-11-28 06:52

    An even better way (and one that is used in the system to launch Browser.apk along with other apps that aren't bundled with AOSP):

    Intent intent = new Intent();
    intent.setClassName("com.android.browser","com.android.BrowserActivity");
    
    context.startActivity(intent);
    

    Alternatively, if you want to check that you can start the Activity from the command line, you can do something like this from your shell:

    adb shell
    am start com.android.browser/.BrowserActivity
    

提交回复
热议问题