【问题标题】:Widget launching a second instance of application小部件启动应用程序的第二个实例
【发布时间】:2010-12-04 22:20:42
【问题描述】:

单击小部件时,我无法从小部件启动应用程序。 这是一段代码

// Create an Intent to launch activity
Intent intent = new Intent(context, Entry_MainTabView.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);             
updateViews.setOnClickPendingIntent(R.id.Widget, pendingIntent);

现在来看这个场景。 我启动我的应用程序,退出到主页,然后单击我的小部件。 它启动应用程序的第二个实例,所以当我点击 "back" 时,应用程序消失并显示另一个副本。然后我再次回击,最后回到主屏幕。

如果 ram 中不存在 Intent,我怎样才能让 Intent 只创建一个新实例?

【问题讨论】:

  • 没有 2 个应用程序在运行,有 2 个相同的活动在您的应用程序中运行。在清单中将您的活动声明为单实例。
  • 啊 - 没有注意到清单,现在可以享受了。

标签: android widget


【解决方案1】:

你看过singleInstance and singleTask launch modes of an activity吗? This extract from Pro Android 2 表示没有记录的方法可以确保只有一个小部件实例在运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-24
    相关资源
    最近更新 更多