Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2094741
  • 博文数量: 413
  • 博客积分: 10926
  • 博客等级: 上将
  • 技术积分: 3862
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-09 18:14
文章分类

全部博文(413)

文章存档

2015年(5)

2014年(1)

2013年(5)

2012年(6)

2011年(138)

2010年(85)

2009年(42)

2008年(46)

2007年(26)

2006年(59)

分类: Java

2009-02-13 18:16:40


1, Set application launch mode in AndroidManifest.xml to implement single instance (More details about launchMode, please refer to ):


              android:label="@string/app_name"
          android:launchMode="singleInstance">
              android:label="Main Window"
          android:icon="@drawable/icon>
       
           
           
       


    



2, If you find single instance doesn't take effect when you install and run your application from Eclipse, please press Run > Run Configurations ...,and select the configuration item of your application on your Eclipse, then select Do Nonthing in group box Launch Action in Android tab. (A launch configuration specifies the project to launch, the Activity to start, the emulator options to use, and so on, please refer to online document http://code.google.com/intl/en-CN/android/intro/develop-and-debug.html in section Create a Launch Configuration to get more details)


3, If your application is not launched manually by clicking application's icon in Android applications list, ie, BroadcaseReceiver launches your application, you need to set correct action and category before launch application as following:
   public class MyReceiver extends BroadcastReceiver
{
    public void onReceive(Context context, Intent intent)
    {
        if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))
        {
            //Phase 2: Launch an activity
            Intent newIntent = new Intent(this, Main.class);  //Activity name
            newIntent.setAction("android.intent.action.MAIN"); //Activity action defined in AndroidManifest.xml
            newIntent.setCategory("android.intent.category.LAUNCHER");//Activity category defined in AndroidManifest.xml
            newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(newIntent);
        }
    }
}
阅读(2574) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~