Android resolves a bug that occurs after QQ shares return to the program

Source: Internet
Author: User

Question: When we use QQ sharing, after sharing the success of the choice to stay in QQ, this time press home button, back to the main screen of the phone, in the click Back to my app, this time will appear the interface display, but any event is not responding, that is, the button did not respond.

Analysis: This time back to our app, we will find the activity life cycle only go Onrestart ()---onStart (), go here to the end, Onresume () did not execute, so the interface does not respond

At this time, we will find that QQ shares the use of a assistactivity its life cycle:.:--onactivityresult ()---onStart ()---onresume ()

Conclusion: So far, we have found the reason, is this assistactivity problem.

WORKAROUND: We can judge the OnStart () method of our program if the assistactivity is at the top of the stack and clears it off.

 @Overrideprotected void OnStart () {Super.onstart ();    LOG.I ("---share----", "-----start");        if (Isneedrestart ()) {Intent Intent = new Intent (context, This.getclass ()); Intent.addflags (Intent.flag_activity_clear_top); Remove the ACTIVITY intent.addflags (intent.flag_activity_no_animation) from the top of the stack;//do not show extra animations, pretend not to restart//remember to bring the required parameters Startactiv    ity (Intent); }}
Private Boolean Isneedrestart () {    Activitymanager am = (activitymanager) context.getsystemservice ( Context.activity_service);    list<activitymanager.runningtaskinfo> tasks = am.getrunningtasks (1);    if (!tasks.isempty ()) {        ComponentName topactivity = tasks.get (0). topactivity;        Activitymanager.runningtaskinfo taskinfo = tasks.get (0);        if (Topactivity.getpackagename (). Equals (Context.getpackagename ())) {        //If the current stack top interface is assistactivity, you need to manually close the            if (Topactivity.getclassname (). Equals ("Com.tencent.connect.common.AssistActivity"))            return true;        }    }    return false;}

Android resolves a bug that occurs after QQ shares return to the program

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.