• QQ
  • nahooten@sina.com
  • 常州市九洲新世界花苑15-2

技术天地



常州手机App开发-Android使用间跳转

原创内容,转载请注明原文网址:http://homeqin.cn/a/wenzhangboke/jishutiandi/2019/0321/418.html



常州手机App开发-Android使用间跳转

 
 
/**



 * 



* @ClassName: MainActivity



* @Description: 从一个使用跳转到另一个使用



* @author huantian



* @email huantian@sina.com



* @date 2019-3-9 下午15:38:12


*



 */



public class MainActivity extends Activity {



 



    private Intent intent = null;



    @Override



    protected void onCreate(Bundle savedInstanceState) {



        super.onCreate(savedInstanceState);



        setContentView(R.layout.activity_main);



        //知道要跳转使用的包名、类名



//        ComponentName comp = new ComponentName("com.huan.tian", "com.huan.tian.MainActivity");



//        final Intent intent = new Intent();



//        intent.setComponent(comp);



//        intent.setAction("android.intent.action.VIEW");



        //不知道类名



        PackageManager pm = getPackageManager();



        PackageInfo pi = null;



        try {



            pi = pm.getPackageInfo("com.huan.tian", 0);



        } catch (NameNotFoundException e) {



            e.printStackTrace();



        }



        



          Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); 



          resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER); 



          resolveIntent.setPackage(pi.packageName); 



 



          //找到匹配intent的一切Activity,这个办法能够在intent跳转前调用用来检测是否有契合条件的activity



          List<ResolveInfo> apps = pm.queryIntentActivities(resolveIntent, 0);



          ResolveInfo ri = apps.iterator().next(); 



          if (ri != null ) { 



              String className = ri.activityInfo.name; 



 



              intent = new Intent(Intent.ACTION_MAIN); 



              intent.addCategory(Intent.CATEGORY_LAUNCHER); 



 



              ComponentName cn = new ComponentName("com.huan.tian", className); 



 



              intent.setComponent(cn); 



          } 



        Button button = (Button) findViewById(R.id.btn_jump);



        button.setOnClickListener(new OnClickListener() {



            



            @Override



            public void onClick(View v) {



                startActivity(intent);



            }



        });



    }


}

上篇:上一篇:Fatal error encountered during command execution解决
下篇:下一篇:如何避免织梦表单反复提交屡次,歹意提交