Cannot start new Intent by setClassName with different package in Android

前端 未结 9 1550
独厮守ぢ
独厮守ぢ 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:55

    intent.setClassName(packageName, className);

    where
    packageName - The name of the package implementing the desired component, i.e. the package where the caller belongs to.
    className - fully qualified name of the class [from different package]

    Calling from com.example.pkg2.Act:

    intent.setClassName("com.example.pkg2", "com.example.pkg1.Act1");
    

提交回复
热议问题