ComponentName类的构造函数是ComponentName(String pkg, String cls),书上的一个实例给的是:ComponentName cn = new ComponentName(MainActivity.this, "com.test.app.MyActivity");
这样的话就是说MainActivity.this应该是指一个包而不是一个类?

解决方案 »

  1.   

    pkg: The name of the package that the component exists in. Can not be null.ComponentName(String pkg, String cls),这里的pkg应该是package name 包名而你写的书上的实例ComponentName cn = new ComponentName(MainActivity.this, "com.test.app.MyActivity");是另一个构造函数 ComponentName cn=new ComponentName(Context pkg, String cls);
    这里的pkg是 一个包的Context----------A Context for the package implementing the component, from which the actual package name will be retrieved.