2011-08-15 73 views
0

对于我的新闻阅读器应用程序,我制作了一个小部件。使用小部件可以启动新闻应用程序。但是,如果用户回到主屏幕,使用后退按钮,仍然有应用程序的实例。因此,如果用户进入应用程序列表(所有应用程序)并再次启动新闻应用程序。新闻应用程序有两个实例:S要关闭应用程序,用户需要在后退按钮上按两次(因为您看到的是同一应用程序的两倍)。我能做些什么吗?一次打开主要活动

这里我的代码:

static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, 
     int appWidgetId) { 


    Intent configIntent = new Intent(context, Main.class); 
    PendingIntent configPendingIntent = PendingIntent.getActivity(context, 0, configIntent, 0); 

    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); 

    remoteViews.setOnClickPendingIntent(R.id.headlinesBox, configPendingIntent); 

    // Tell the widget manager 
    appWidgetManager.updateAppWidget(appWidgetId, remoteViews); 

}

回答

0

看来你必须添加到清单:

<activity android:name=".Main" 
       android:launchMode="singleInstance"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"/> 
     </intent-filter> 
    </activity> 
0

您可以在清单文件上android:clearTaskOnLaunch活动属性设置为true。

它应该总是关闭所有额外的活动并从第一个活动启动应用程序。

+0

遗憾的是不工作..:S – Johan

相关问题