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