机器人 : get an singleTask activity from background to foreground

标签 android android-activity

我正在使用 phonegap 和移动 jquery 开发一个应用。

我的应用程序在后台运行,如果事件从 js 触发,我想让我的应用程序进入前台。

如何让我的应用程序从后台转到前台。我有一个具有以下属性的 Activity :

android:configChanges="orientation|keyboardHidden|screenLayout"
        android:screenOrientation="portrait"
        android:windowSoftInputMode="adjustPan" 
        android:launchMode="singleTask"        
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar"

我试图让我的应用程序处于前台的是:

    Intent intent = new Intent(mContext , MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    mContext.startActivity(intent);

mContext.startActivity(((Activity)mContext).getIntent());

(MainActivity 是我的应用程序中唯一的 Activity )但它不工作。我使用的是 android 4.0。

更新:在 android 2.3 中它工作正常但在 android 4.0 中不工作

最佳答案

经过一番努力,我找到了解决方案...... 我实现了一个广播监听器。当我收到任何事件时,我会发送一个广播,并在广播接收器中启动该应用程序。

Intent intent = new Intent(mContext, NotificationBroadcastReceiver.class);
        mContext.sendBroadcast(intent);

** 接收者** :

public final class NotificationBroadcastReceiver  extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
         System.out.println("Broadcast recieved");
         context.startActivity(new Intent(context,A.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
      }
}

关于机器人 : get an singleTask activity from background to foreground,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12090208/

相关文章:

java - 如何停止从网络服务器接收数据?

android - 如何点击外部链接打开特定应用程序的特定 Activity ?

android - 在 Android 委托(delegate)之前拦截 Intent (NFC)

android - 包含速度信息的 GPX 文件

android - 在没有 bindAppWidgetId() 的情况下将小部件添加到启动器页面

android - 背景大小 : auto not working as expected on android 6

android - 为什么在 Android 中不调用 onActivityResult?

android - 空对象引用上的 void android.view.View.dispatchWindowVisibilityChanged(int)'

android - 是否可以加载部分谷歌地图供离线使用?

android - savedInstanceState 返回 null