`

CompentName

阅读更多

 通过intent类来获取组件,继而取得组件的包名和类名:          

              Intent intent = this.getIntent();// 获得Intent 
              // 获得组件名称对象 
              ComponentName componentName = intent.getComponent(); 
              // 获得包名称 
              String pkgName = componentName.getPackageName(); 
              // 获得类名称 
              String clsName = componentName.getClassName

 

 

创建CompentName的几种方式:

                       // 通过上下文和类名创建ComponetName 

                         CompentName CompentName = new CompentName ( 

                          MainActivity.this, MyActivity.class); 

                            // 通过包名和类名创建ComponetName 

                            // CompentName CompentName = new CompentName ( 

                            // "com.jiahui.activity", "com.jiahui.activity.MyActivity"); 

 

 

 

                            // Intent intent = new Intent(); 

                            // 通过上下文和类名创建ComponetName 

                            // CompentName CompentName = new CompentName ( 

                            // MainActivity.this, "com.jiahui.activity.MyActivity");  

                            Intent intent = new Intent(); 

                           // 通过Intent的setComponet指定组件名称 

                           intent.CompentName (componentName);               

                            // 启动Activity 

                            startActivity(intent); 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics