[Android] onNewIntent call time

Source: Internet
Author: User

Override the following methods in IntentActivity: onCreate onStart onRestart onResume onPause onStop onDestroy onNewIntent 1. If other applications send Intent, run the following methods: I // @ philn (12410 ): onCreateI/@ philn (12410): onStartI/@ philn (12410): onResume Method for sending Intent: Uri uri Uri = Uri. parse ("http://www.cnblogs.com/rayray/"); Intent it = new Intent (Intent. ACTION_VIEW, uri); startActivity (it); 2. Receive Intent declaration: <activity android: name = ". intentActivity "android: launchMod E = "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 to say, the previously opened Activity is now in the I/@ philn (12410): onPauseI/@ philn (12410): onStop status. If Intent is ressent, the execution sequence is: I/@ philn (12410): onNewIntentI/@ philn (12410): onRestartI/@ philn (12410 ): onStartI/@ philn (12410): During Android Application Development, onResume starts another Activity from one Activity and transmits 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. In order not to let the Activity be instantiated multiple times, we need to go through AndroidManifest. xml configures the activity loading mode (launchMode) to implement the single task mode, as shown below: <activity android: label = "@ string/app_name" android: launchmode = "singleTask" android: when name = "Activity1"> </activity> launchMode is singleTask, an Activity is started through Intent. If the system already has an instance, the system sends the request to the instance, however, at this time, the system will not call the onCreate method for processing the request data, but call the onNewIntent method, as shown below: copy the Code protected void onNewIntent (Intent intent) {super. onNewIntent (intent); setIntent (intent); // must store the new intent unless getIntent () will return the old one processExtraData ();} Do not forget to copy the code, 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: copy the code public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); processExtraData ();} protected void onNewIntent (Intent intent) {super. onNewIntent (intent); setIntent (intent); // must store the new intent unless getIntent () will return the old one processExtraData ()} private void processExtraData () {Intent intent = getIntent (); // use the data already Ed here}

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.