Intent case (system BUG) caused by "OPEN" after Android software is installed)

Source: Internet
Author: User

 

Prepared by: Xu jianxiang (netpirate@gmail.com)

Date: 2010/12/13

Web: http://www.anymobile.org

 

 

There are many entry points for opening a program:

 

Run the shell command line;

Launcher standby interface execution;

The status notification bar is running;

Desktop Shortcut running;

Call and run in software;

 

Run "open" after installing the software!

 

The code for calling the program is as follows (see COM. Android. launcher/. launcher. Java ):

 

Intent intent = new Intent (this, TestActivity. class); <br/> intent. setAction (Intent. ACTION_MAIN); <br/> intent. addCategory (Intent. CATEGORY_LAUNCHER); <br/> intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); <br/> intent. addFlags (Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); <br/> this. startActivity (intent ); 

 

After installing the software, click "open" to call the code as follows (see COM. Android. packageinstaller/. installappdone. Java ):

 

Intent intent = new Intent (this, TestActivity. class); <br/> this. startActivity (intent ); 

 

If you execute "open" immediately after installing the software, run the program, press the Home Key to return to the background, and then run the program in several other ways, then another main program will be started. This is because the intent processing mechanism is: Compare activity first, then compare action, flag, bnds ..., the two methods have different actions. One has a launcher action and the other does not. Therefore, they are considered to start two different intents.

 

Currently, only one simple processing method is available:

 

Main Program: splashactivity. Java

Original program entry program: loginactivity. Java

 

After the program is started, add a quick notification in the status notification bar. The Code is as follows:

 

Package Org. anymobile. test; <br/> Import android. app. activity; <br/> Import android. app. notification; <br/> Import android. app. icationicationmanager; <br/> Import android. app. pendingintent; <br/> Import android. content. componentname; <br/> Import android. content. context; <br/> Import android. content. intent; <br/> Import android. OS. bundle; <br/> public class splashactivity extends activity <br/>{< br/> @ overrid E <br/> protected void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); </P> <p> This. shownotification (this. getbasecontext (),-1, "test is running! "," Test start up! "); </P> <p> intent = This. getintent (); <br/> If (intent. hascategory (intent. category_launcher) <br/>{< br/> intent = new intent (this, testactivity. class); <br/> This. startactivity (intent); <br/>}< br/> else <br/>{< br/> intent = new intent (); <br/> componentname = new componentname (this, splashactivity. class); <br/> intent. setcomponent (componentname); <br/> // intent = new intent (this, splashactivity. class); </P> <p> intent. setaction (intent. action_main); <br/> intent. addcategory (intent. category_launcher); <br/> intent. addflags (intent. flag_activity_new_task); <br/> intent. addflags (intent. flag_activity_reset_task_if_needed); </P> <p> This. startactivity (intent); <br/>}</P> <p> This. finish (); <br/>}< br/> Public void shownotification (context, int iresicon, string snotifybar, string snofitymsg) <br/>{< br/> // look up the notification Manager Service <br/> icationicationmanager Nm = (icationicationmanager) context. getsystemservice (context. notification_service); <br/> // the details of our fake message <br/> charsequence from = "test"; <br/> charsequence message = snofitymsg; </P> <p> intent = new intent (); <br/> componentname = new componentname (context, testactivity. class); <br/> intent. setcomponent (componentname); </P> <p> intent. setaction (intent. action_main); <br/> intent. addcategory (intent. category_launcher); <br/> intent. addflags (intent. flag_activity_new_task); <br/> intent. addflags (intent. flag_activity_reset_task_if_needed); </P> <p> pendingintent contentintent = pendingintent. getactivity (context, 0, intent, 0); <br/> Notification = <br/> new notification (iresicon, snotifybar, system. currenttimemillis (); <br/> notification. flags = notification. flags | notification. flag_ongoing_event; <br/> notification. defaults = <br/>/* notification. default_sound | */notification. default_lights; <br/> notification. setlatesteventinfo (context, from, message, contentintent); <br/> nm. notify (R. string. app_name, notification); <br/>}< br/> @ override <br/> protected void onstart () <br/> {<br/> // todo auto-generated method stub <br/> super. onstart (); <br/>}< br/> @ override <br/> protected void onresume () <br/> {<br/> // todo auto-generated method stub <br/> super. onresume (); <br/>}< br/> @ override <br/> protected void onstop () <br/> {<br/> // todo auto-generated method stub <br/> super. onstop (); <br/>}< br/> @ override <br/> protected void ondestroy () <br/> {<br/> // todo auto-generated method stub <br/> super. ondestroy (); <br/>}< br/> 

 

Package org. anymobile. test; <br/> import android. app. activity; <br/> // import android. content. componentName; <br/> import android. content. intent; <br/> import android. graphics. lightingColorFilter; <br/> import android. OS. bundle; <br/> import android. view. menu; <br/> import android. view. view; <br/> import android. view. view. onClickListener; <br/> import android. widget. button; <br/> public class TestActivity ex Tends Activity <br/>{< br/> private static final int ADD_ID = 0; <br/> private static final int DEL_ID = 1; </p> <p>/** Called when the activity is first created. */<br/> @ Override <br/> public void onCreate (Bundle savedInstanceState) <br/>{< br/> Intent intent = this. getIntent (); <br/> if (! Intent. hasCategory (Intent. CATEGORY_LAUNCHER) <br/>{< br/> this. getIntent (). addCategory (Intent. CATEGORY_LAUNCHER); <br/>}< br/> this. getWindow (). addFlags (CONTEXT_IGNORE_SECURITY); </p> <p> super. onCreate (savedInstanceState); <br/> setContentView (R. layout. main); </p> <p> Button button = (Button) this. findViewById (R. id. btn_menu); <br/> button. setOnClickListener (new OnClickListener () <br/>{< br/> public void onClick (View v) <br/>{< br/> // TestActivity. this. openOptionsMenu (); </p> <p> // String packName = "com. longcheer. imm "; <br/> // String className = packName + ". activitys. loginActivity "; <br/> // Intent intent = new Intent (); <br/> // ComponentName componentName = new ComponentName (packName, className ); <br/> // intent. setComponent (componentName); <br/> // intent. setAction ("android. intent. action. MAIN "); <br/> // intent. addCategory ("android. intent. category. LAUNCHER "); <br/> // intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); <br/> // intent. addFlags (Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); <br/> // TestActivity. this. startActivity (intent); </p> <p> Intent intent = new Intent (TestActivity. this, Test2Activity. class); <br/> TestActivity. this. startActivity (intent); <br/> TestActivity. this. finish (); <br/>}< br/>}); <br/> // button. getBackground (). setColorFilter (0xFFFF0000, PorterDuff. mode. MULTIPLY); <br/> button. getBackground (). setColorFilter (new LightingColorFilter (0 xFFFFFFFF, 0xFFAA0000); <br/>}< br/> @ Override <br/> protected void onRestoreInstanceState (Bundle savedInstanceState) {<br/> // TODO Auto-generated method stub <br/> super. onRestoreInstanceState (savedInstanceState); <br/>}< br/> @ Override <br/> protected void onSaveInstanceState (Bundle outState) {<br/> // TODO Auto-generated method stub <br/> super. onSaveInstanceState (outState); <br/>}< br/> @ Override <br/> public boolean onCreateOptionsMenu (Menu menu) <br/>{< br/> menu. add (0, ADD_ID, 0, "ADD"); <br/> menu. add (0, DEL_ID, 0, "DEL"); </p> <p> return super. onCreateOptionsMenu (menu); <br/>}</p> <p>} 

 

Package org. anymobile. test; <br/> import android. app. activity; <br/> import android. content. componentName; <br/> import android. content. context; <br/> import android. content. intent; <br/> import android. graphics. lightingColorFilter; <br/> import android. OS. bundle; <br/> import android. text. clipboardManager; <br/> import android. view. menu; <br/> import android. view. view; <br/> import android. view. view. onClickListener; <br/> import android. widget. button; <br/> public class Test2Activity extends Activity <br/>{< br/> private static final int ADD_ID = 0; <br/> private static final int DEL_ID = 1; </p> <p>/** Called when the activity is first created. */<br/> @ Override <br/> public void onCreate (Bundle savedInstanceState) <br/>{< br/> super. onCreate (savedInstanceState); <br/> setContentView (R. layout. main); </p> <p> ClipboardManager clip = (ClipboardManager) getSystemService (Context. CLIPBOARD_SERVICE); </p> <p> Button button = (Button) this. findViewById (R. id. btn_menu); <br/> button. setText ("22222222"); <br/> button. setOnClickListener (new OnClickListener () <br/>{< br/> public void onClick (View v) <br/>{< br/> Test2Activity. this. openOptionsMenu (); <br/> // String packName = "com. longcheer. imm "; <br/> // String className = packName + ". activitys. loginActivity "; <br/> // Intent intent = new Intent (); <br/> // ComponentName componentName = new ComponentName (packName, className ); <br/> // intent. setComponent (componentName); <br/> // intent. setAction ("android. intent. action. MAIN "); <br/> // intent. addCategory ("android. intent. category. LAUNCHER "); <br/> // intent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK); <br/> // intent. addFlags (Intent. FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); <br/> // Test2Activity. this. startActivity (intent); <br/>}< br/>}); <br/> // button. getBackground (). setColorFilter (0xFFFF0000, PorterDuff. mode. MULTIPLY); <br/> button. getBackground (). setColorFilter (new LightingColorFilter (0 xFFFFFFFF, 0xFFAA0000); <br/>}< br/> @ Override <br/> public boolean onCreateOptionsMenu (Menu menu) <br/>{< br/> menu. add (0, ADD_ID, 0, "ADD2"); <br/> menu. add (0, DEL_ID, 0, "DEL2"); </p> <p> return super. onCreateOptionsMenu (menu); <br/>}</p> <p>} 

 

Test process:

 

A. install the software locally;

B. Run "open" after installation ";

C. The running software adds noticification testactivity from splashactivity;

D. Jump to splashactivity (with launcher action );

E. Jump to testactivity;

F. click the button to jump to test2activity;

G. In the drop-down notification bar, click program notification to run the program normally.

 

Todo: after the software is installed and the open command is executed, the program will still start two identical activities from the standby interface. This problem is not solved! :(

 

 

 

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.