我正在使用 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/