Android 安装软件后执行“OPEN”引起的Intent血案(系统BUG)
2010-12-13 22:30
821 查看
编写:徐建祥(netpirate@gmail.com)
日期:2010/12/13
网址:http://www.anymobile.org
打开程序的入口有很多个:
shell 命令行运行;
Launcher待机界面执行;
状态通知栏运行;
桌面快捷方式运行;
软件中调用运行;
安装软件后执行“OPEN”运行!
前面几项,调用程序的代码如下(参考:com.android.Launcher/.Launcher.java):
而安装软件后,点击“Open”调用的代码如下(参考:com.android.packageinstaller/.InstallAppDone.java):
如果用户安装软件后立刻执行“Open”,运行程序后,按HOME键返回到后台,然后再通过别的几种方法运行程序,则会再起一个MAIN程序。这是因为Intent的处理机制是,先比较Activity,再比较Action、Flag、bnds。。。,前后两张方式的Action不一样,一个有LAUNCHER ACTION,一个没有,所以会认为是启动两个不同的INTENT。
目前只想到一个简单的处理方式:
程序入口MAIN程序:SplashActivity.java
程序原入口程序:LoginActivity.java
启动程序后,在状态通知栏上添加快捷通知,代码如下:
测试流程:
a、软件本地安装;
b、安装后执行“Open”;
c、运行软件会从SplashActivity添加NOTICIFICATION TestActivity;
d、跳转至SplashActivity(附带LAUNCHER ACTION);
e、再跳转至TestActivity;
f、点击BUTTON,跳转至Test2Activity;
g、下拉状态通知栏,点击程序通知,可以正常运行程序。
TODO: 安装软件后执行OPEN后,从待机界面运行程序,还是会启动两个一样的ACTIVITY,这个问题没有解决!:(
日期:2010/12/13
网址:http://www.anymobile.org
打开程序的入口有很多个:
shell 命令行运行;
Launcher待机界面执行;
状态通知栏运行;
桌面快捷方式运行;
软件中调用运行;
安装软件后执行“OPEN”运行!
前面几项,调用程序的代码如下(参考:com.android.Launcher/.Launcher.java):
Intent intent = new Intent(this, TestActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); this.startActivity(intent);
而安装软件后,点击“Open”调用的代码如下(参考:com.android.packageinstaller/.InstallAppDone.java):
Intent intent = new Intent(this, TestActivity.class); this.startActivity(intent);
如果用户安装软件后立刻执行“Open”,运行程序后,按HOME键返回到后台,然后再通过别的几种方法运行程序,则会再起一个MAIN程序。这是因为Intent的处理机制是,先比较Activity,再比较Action、Flag、bnds。。。,前后两张方式的Action不一样,一个有LAUNCHER ACTION,一个没有,所以会认为是启动两个不同的INTENT。
目前只想到一个简单的处理方式:
程序入口MAIN程序:SplashActivity.java
程序原入口程序:LoginActivity.java
启动程序后,在状态通知栏上添加快捷通知,代码如下:
package org.anymobile.test; import android.app.Activity; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; public class SplashActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.showNotification(this.getBaseContext(), -1, "Test is Running!", "Test Start Up!"); Intent intent = this.getIntent(); if (intent.hasCategory(Intent.CATEGORY_LAUNCHER)) { intent = new Intent(this, TestActivity.class); this.startActivity(intent); } else { intent = new Intent(); ComponentName componentName = new ComponentName(this, SplashActivity.class); intent.setComponent(componentName); // intent = new Intent(this, SplashActivity.class); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); this.startActivity(intent); } this.finish(); } public void showNotification(Context context,int iResIcon,String sNotifybar,String sNofitymsg) { // look up the notification manager service NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); // The details of our fake message CharSequence from = "Test"; CharSequence message = sNofitymsg; Intent intent = new Intent(); ComponentName componentName = new ComponentName(context, TestActivity.class); intent.setComponent(componentName); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0); Notification notification = new Notification(iResIcon,sNotifybar, System.currentTimeMillis()); notification.flags = notification.flags | Notification.FLAG_ONGOING_EVENT; notification.defaults = /*Notification.DEFAULT_SOUND|*/Notification.DEFAULT_LIGHTS; notification.setLatestEventInfo(context, from, message, contentIntent); nm.notify(R.string.app_name, notification); } @Override protected void onStart() { // TODO Auto-generated method stub super.onStart(); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); } @Override protected void onStop() { // TODO Auto-generated method stub super.onStop(); } @Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); } }
package org.anymobile.test; import android.app.Activity; //import android.content.ComponentName; import android.content.Intent; import android.graphics.LightingColorFilter; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class TestActivity extends Activity { private static final int ADD_ID = 0; private static final int DEL_ID = 1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { Intent intent = this.getIntent(); if (! intent.hasCategory(Intent.CATEGORY_LAUNCHER)) { this.getIntent().addCategory(Intent.CATEGORY_LAUNCHER); } this.getWindow().addFlags(CONTEXT_IGNORE_SECURITY); super.onCreate(savedInstanceState); setContentView(R.layout.main); Button button = (Button) this.findViewById(R.id.btn_menu); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TestActivity.this.openOptionsMenu(); // String packName = "com.longcheer.imm"; // String className = packName + ".activitys.LoginActivity"; // // Intent intent = new Intent(); // ComponentName componentName = new ComponentName(packName, className); // intent.setComponent(componentName); // // intent.setAction("android.intent.action.MAIN"); // intent.addCategory("android.intent.category.LAUNCHER"); // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); // // TestActivity.this.startActivity(intent); Intent intent = new Intent(TestActivity.this, Test2Activity.class); TestActivity.this.startActivity(intent); TestActivity.this.finish(); } }); // button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY); button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000)); } @Override protected void onRestoreInstanceState(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onRestoreInstanceState(savedInstanceState); } @Override protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub super.onSaveInstanceState(outState); } @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, ADD_ID, 0, "ADD"); menu.add(0, DEL_ID, 0, "DEL"); return super.onCreateOptionsMenu(menu); } }
package org.anymobile.test; import android.app.Activity; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.graphics.LightingColorFilter; import android.os.Bundle; import android.text.ClipboardManager; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Test2Activity extends Activity { private static final int ADD_ID = 0; private static final int DEL_ID = 1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ClipboardManager clip = (ClipboardManager)getSystemService(Context.CLIPBOARD_SERVICE); Button button = (Button) this.findViewById(R.id.btn_menu); button.setText("22222222"); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Test2Activity.this.openOptionsMenu(); // String packName = "com.longcheer.imm"; // String className = packName + ".activitys.LoginActivity"; // // Intent intent = new Intent(); // ComponentName componentName = new ComponentName(packName, className); // intent.setComponent(componentName); // // intent.setAction("android.intent.action.MAIN"); // intent.addCategory("android.intent.category.LAUNCHER"); // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // intent.addFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); // // Test2Activity.this.startActivity(intent); } }); // button.getBackground().setColorFilter(0xFFFF0000, PorterDuff.Mode.MULTIPLY); button.getBackground().setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0xFFAA0000)); } @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, ADD_ID, 0, "ADD2"); menu.add(0, DEL_ID, 0, "DEL2"); return super.onCreateOptionsMenu(menu); } }
测试流程:
a、软件本地安装;
b、安装后执行“Open”;
c、运行软件会从SplashActivity添加NOTICIFICATION TestActivity;
d、跳转至SplashActivity(附带LAUNCHER ACTION);
e、再跳转至TestActivity;
f、点击BUTTON,跳转至Test2Activity;
g、下拉状态通知栏,点击程序通知,可以正常运行程序。
TODO: 安装软件后执行OPEN后,从待机界面运行程序,还是会启动两个一样的ACTIVITY,这个问题没有解决!:(
相关文章推荐
- 在redhat系统中安装g++(执行c++的程序)等软件时报错的解决方法
- android的系统存储与软件安装
- Android获取系统已安装应用软件程序(apk)信息
- Android获取系统已安装应用软件程序(apk)信息
- android 5.0以下系统Intent传递序列化对象的bug
- Android 删除内置软件 或者将app安装到系统中,不能卸载
- 如何改变Android手机软件安装位置 给android系统扩容
- 调用Android系统安装的软件打开文件,程序停止运行
- ubuntu系统下,android虚拟机安装软件:adb install的比较安装APK的方法
- Bug Fix : 安装Visual Studio SP6后引起的ASP无法执行, ASP运行后出现500 - internal error.
- Android----Intent,运用由android系统帮助匹配实现打电话、发送短信、打开网页、播放音乐、打开视频、打开图片、安装APK、通知栏消息、拍照上传头像等功能
- Android 边用边学 之 获取系统内安装的软件信息
- 调用Android系统安装的软件打开文件,程序停止运行
- Bug Fix : 安装Visual Studio SP6后引起的ASP无法执行, ASP运行后出现500 - internal error.
- Android软件卸载安装分享等
- Bug跟踪系统 JTrac 安装与配置说明
- RedHat 未注册的服务系统使用yum命令进行软件安装
- Android:系统或JDK为32位时安装Android Studio
- Android调用系统Intent进行图片选取裁剪
- linux系统中安装软件的方法+yum仓库+yum源+epel源