The jump of activity is often involved in Android. How to implement jump in Android, as follows.
Creating the second activity is to create a class, inherit from.
When creating the second activity, you need to configure it in the manifest file, otherwise you will not be able to find it.
<activity android:name=""></activity>
The entry activity has the following code. As long as the activity has the following code, an icon will be created. The default icon is the same
The icon name can be set through android:lable="".
<intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter>
If the package where the activity is located is the same as the application package name, it can be ignored.
The configuration in the complete list is as follows:
<activity android:name="" android:label="@string/app_name" > <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity>
Implicit jump and display jump
Show jump to activity
The following configuration is required to display the manifest file in the jump
<activity android:name=""></activity>
The implementation in the code is as follows
/* * Jump to the activity in this application * Display jump: directly specify the package name and class name of the target activity */ public void click2(View v){ Intent intent = new Intent(); //The first parameter is the context object, and the second parameter is the class name of the target activity to be formulated //Show intention (this, ); startActivity(intent); }
Implicitly jump to activity
There are 3 parameters in the intent-filter action, category, and data. Action and data can be configured multiple times. category is the system configuration, and the name in the action is defined by oneself. After defining the value of the name is the action of the activity. When the activity is implicitly started, the configuration in the intention must be consistent with the name of the action here. data is the parameter carried during the jump process, and mimeType is the type of data carried. According to the configuration in the intention filter, different processing is required for the configuration of data during the jump.
<activity android:name=""> <intent-filter> <action android:name=""/> <span style="white-space:pre"> </span> <action android:name=""/> <span style="white-space:pre"> </span> <data android:scheme="ldw" android:mimeType="text/password"/> <category android:name=""/> </intent-filter> </activity>
The implementation in the code is as follows
/* * Implicitly jump to dial secondActivity */ public void click5(View v){ <span style="white-space:pre"> </span>Intent intent = new Intent(); <span style="white-space:pre"> </span>//The package name and class name of the target activity <span style="white-space:pre"> </span>(""); <span style="white-space:pre"> </span>(("ldw:canshu")); //The parameters in the scheme are plus colons, and the configuration when there is no miniType <span style="white-space:pre"> </span>//("text/password");//Configuration when data is not configured but miniType is available <span style="white-space:pre"> </span>//(("ldw:canshu"), "text/password");// Both data and miniType are sometimes <span style="white-space:pre"> </span>(Intent.CATEGORY_DEFAULT);//If you don't write this sentence, the system will add the default category <span style="white-space:pre"> </span>startActivity(intent); }
Methods to get the passed parameters in activity:
package ; import ; import ; import ; import ; public class SecondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState){ (savedInstanceState); setContentView(.activity_second); //Get the intention to start this activity Intent intent = getIntent(); //Get the passed data Uri uri = (); } }
How to choose which startup method: Starting the activity in the same application is suitable for display, and starting the activity in different applications is suitable for implicit. There is no problem with using implicitly all, and the use of display is more efficient. When multiple activities in the system match the action set by the intended setting, a dialog box will pop up containing the matching activities.
Configuration of the call application
/* * Jump to call activity * Implicit jump: Jump by formulating action and data */ public void click1(View v){ Intent intent = new Intent(); //Implicit Intent (Intent.ACTION_CALL); (("tel:1190")); //Jump startActivity(intent); } /* * Show jump to dialer */ public void click3(View v){ Intent intent = new Intent(); //The package name and class name of the target activity ("", ".DialtactsActivity"); startActivity(intent); }
How to start the browser
/* * Show jump to browser */ public void click6(View v){ <span style="white-space: pre;"> </span>Intent intent = new Intent(); <span style="white-space: pre;"> </span>//The package name and class name of the target activity <span style="white-space: pre;"> </span>("",""); <span style="white-space: pre;"> </span>startActivity(intent); } /* * Implicitly jump to the browser */ public void click7(View v){ <span style="white-space: pre;"> </span>Intent intent = new Intent(); <span style="white-space: pre;"> </span>//The package name and class name of the target activity <span style="white-space: pre;"> </span>(intent.ACTION_VIEW); <span style="white-space: pre;"> </span>(("")); <span style="white-space: pre;"> </span>startActivity(intent); }
The above is the implicit jump of Activity in Android introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!