Android Onresultactivity does not perform cause summary

Source: Internet
Author: User

Plug in a note. When using arrayadapter data there must be a type of list<string> that cannot be arraylist<string>

1. After calling startactivityforresult () in a.activity to start b.activity, after the Setresult () method is called in B.activity, A. The onresultactivity in the activity will be executed.

However, you will not be able to perform the following problems:

  Startactivityforresult () Usage reference: http://www.cnblogs.com/liangstudyhome/p/3708296.html

    •   Activity is initiated by singletask or Singlemode
    • Requescode less than 0 in the passed intent
    • * * * is in the Startactivityforresult () activity in a groupactivity (in fact, the implementation of Groupactivity onresultactivity method)

2. solutions to the above problems:

    •   Change the way activity starts to Stander

1. Tab activity (child activity that wants to get the onresultactivity value) is used in

  

1 getParent (). Startactivityforresult (Intent,request);  


2. When the sub-Activity.finish is returned, the Onactivityresult is implemented in Activitygroup, similar to the following:

  

1 @Override2         protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {  3             //Pass down4Youractivity currentactivity =(youractivity) Getlocalactivitymanager ()5 . getcurrentactivity (); 6 Currentactivity.onchildactivityresult (Requestcode, ResultCode, data); 7}

Onchildactivityresult is a method that you implement yourself to handle the returned results.

A specific example:

  

1@SuppressWarnings ("Deprecation")2     Private voidTabchange (Compoundbutton Buttonview,BooleanisChecked) {3         if(isChecked) {4 containerbordy.removeallviews ();5Intent Intent =NULL;6             Switch(Buttonview.getid ()) {7              CaseR.id.tab_weather:8 9Intent =NewIntent (Mainactivitytab. This,TenWeatheractivitybaidu.class); One                  Break; A              CaseR.id.tab_produce: -  -Intent =NewIntent (Mainactivitytab. This, theProductwarningactivity.class); -                  Break; -              CaseR.id.tab_im: -Intent =NewIntent (Mainactivitytab. This, +Chatbriefactivity.class); -                  Break; +  A              CaseR.id.tab_diaster: atIntent =NewIntent (Mainactivitytab. This, -Relevantforecastactivity.class); -                  Break; -              Caser.id.tab_setting: -Intent =NewIntent (Mainactivitytab. This, Settingactivity.class); -                  Break; in              CaseR.id.tab_more: -  to                  Break; +  -             } the  * intent.setflags (intent.flag_activity_clear_top); $ Panax NotoginsengWindow subactivity = mlam.startactivity ("StartActivity", intent); - Containerbordy.addview (Subactivity.getdecorview ()); the  +         } A  the}

The method above is to load an activity into a groupactivity.

It is important to note that this activity has a startactivity ID, so the Onactivityresult method described above is changed to:

1 @Override2     protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {3         Super. Onactivityresult (Requestcode, ResultCode, data);4SYSTEM.OUT.PRINTLN ("Returned is the onactivityresult here."));5Communicationactivity currentactivity =(communicationactivity) Mlam6. Getactivity ("StartActivity");7         8 //Activity a = mlam.getcurrentactivity ()9System.out.println ("currentactivity-->>" +currentactivity);Ten          One          A //System.out.println ("requestcode-->>" + Requestcode - //+ "resultcode-->>" + ResultCode + "data" - //+ Data.getintextra ("Blockid", 0)); the currentactivity.onactivityresultfrommainactivity (Requestcode, - ResultCode, data); - //Currentactivity.ysos (); -}
The Mlam corresponds to the localactivitymanager.
Onactivityresultfrommainactivity This is a method of its own definition in the child activity.

Android Onresultactivity does not perform cause summary

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.