[Android] onNewIntent call time

Source: Internet
Author: User

Override the following methods in IntentActivity: onCreate onStart onRestart onResume onPause onStop onDestroy onNewIntent
1. Use the following methods to send Intent messages to other applications:
I // @ philn (12410): onCreate
I // @ philn (12410): onStart
I // @ philn (12410): onResume

Intent sending method:
Uri uri = Uri. parse ("http://www.cnblogs.com/rayray ");
Intent it = new Intent (Intent. ACTION_VIEW, uri );
StartActivity (it );

Ii. Receive Intent statement:
<Activity android: name = ". IntentActivity" android: launchMode = "singleTask"
Android: label = "@ string/testname">
<Intent-filter>
<Action android: name = "android. intent. action. VIEW"/>
<Category android: name = "android. intent. category. DEFAULT"/>
<Category android: name = "android. intent. category. BROWSABLE"/>
<Data android: scheme = "http"/>
</Intent-filter>
</Activity>

3. If IntentActivity is at the top of the task stack, that is, the previously opened Activity is currently
I // @ philn (12410): onPause
I // @ philn (12410): The onStop status
If other applications send Intent messages again, the execution sequence is as follows:
I // @ philn (12410): onNewIntent
I // @ philn (12410): onRestart
I // @ philn (12410): onStart
I // @ philn (12410): onResume

 

During Android Application Development, it is very easy to start another Activity from one Activity and transmit some data to the new Activity, however, when you need to bring the Activity running in the background back to the foreground and transmit some data, there may be a small problem.

First, by default, when you start an Activity through Intent, even if the same running Activity already exists, A new Activity instance is created and displayed. To prevent the Activity from being instantiated multiple times, we need to configure the activity loading mode (launchMode) in AndroidManifest. xml to implement the single task mode, as shown below:

 

 


When launchMode is singleTask, an Activity is started through Intent. If the system already has an instance, the system sends the request to the instance, the system will no longer call the onCreate method for processing the request data, but will call the onNewIntent method, as shown below:

 

 

 


Do not forget that the system may kill the Activity running in the background at any time. If this happens, the system will call the onCreate method instead of the onNewIntent method, A good solution is to call the same data processing method in the onCreate and onNewIntent methods, as shown below:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.