Cannot start new Intent by setClassName with different package in Android

前端 未结 9 1552
独厮守ぢ
独厮守ぢ 2020-12-06 11:30

I want to start a new Intent dynamically. Therefore setClassName seems the best choice.

First, I define 3 activity in Manifest



        
9条回答
  •  情书的邮戳
    2020-12-06 11:49

    You can use the following method to create the intent in the package context:

        Intent intent = new Intent(this, MyActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    

    This way you keep on generic code.

    HTH

提交回复
热议问题