常见Android Start Activity用法汇总

来源:互联网 发布:中国新歌声网络直播吗 编辑:程序博客网 时间:2024/04/29 17:23
//Calls another activity, by name, without passing dataIntent iExp = new Intent(this, ActivityToCall.class); //TODO  Replace 'ActivityToCall' with the class name of the activity being calledstartActivity(iExp);

 

//Calls another activity, by action and category, without passing data//refer to AndroidManifest.xml<intent-filter> when determining the action and category of the activity to callIntent iImp = new Intent("actionName"); //TODO Replace 'actionName' as appropriate for your action (for example, Intent.ACTION_EDIT)iImp.addCategory("categoryName"); //TODO Replace 'categoryName' as appropriate for your category (for example, Intent.CATEGORY_DEFAULT)startActivity(iImp);
 
//Calls another activity, identified by action and category, passing data URL and a MIME type//The class calling the snippet code must implement the following method://protected void onActivityResult (int requestCode, int resultCode, Intent data) {}Intent iImp = new Intent();iImp.setAction("actionName"); //TODO Replace 'actionName' as appropriate for your action (for example, Intent.ACTION_EDIT)iImp.addCategory("categoryName"); //TODO Replace 'categoryName' as appropriate for your category (for example, Intent.CATEGORY_DEFAULT)//optional - set data and MIME type for the intentiImp.setDataAndType(Uri.parse("http://com.example.project/folder"), "text/plain"); //TODO Change URL and MIME type as appropriatestartActivityForResult(iImp, 0); //TODO The second parameter (here, zero) is the request code to be used in onActivityResult(); change this parameter to an appropriate value for your activ