[英]Open main-activity one time
For my news-reader app, I made a widget.对于我的新闻阅读器应用程序,我制作了一个小部件。 Using the widget it is possible to start the news-app.
使用小部件可以启动新闻应用程序。 But if the user goes back to the home screen, with the back button, there still is an instance of the application.
但是,如果用户使用返回按钮返回主屏幕,仍然有一个应用程序实例。 So if the user goes the applications-list (all the app's) and start the news-app again.
因此,如果用户进入应用程序列表(所有应用程序)并再次启动新闻应用程序。 There are 2 instances of the news app:S For closing the app, the users needs to push 2 times on the back button (because you see 2 times the same app).
新闻应用有 2 个实例:S 要关闭应用,用户需要按 2 次返回按钮(因为您会看到 2 次同一个应用)。 Can I do anything about it?
我能做些什么吗?
Here my code:这是我的代码:
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);
} }
You can set true on android:clearTaskOnLaunch
activity attribute in the Manifest file.您可以在 Manifest 文件中的
android:clearTaskOnLaunch
活动属性上设置为 true。
It should always close all the extra Activities and start the App from the first Activity.它应该始终关闭所有额外的活动并从第一个活动启动应用程序。
It seems that you have to add to the manifest:看来您必须添加到清单中:
<activity android:name=".Main"
android:launchMode="singleInstance">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
</intent-filter>
</activity>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.