我有一项服务,有时会调用一个显示alertdialog的活动..当点击确定按钮时,我想转到之前在屏幕上的应用程序的活动,或者,如果我的应用程序不在前面,请来回到用户显示的窗口..这是我的alertdialog
public class ActivityNotification extends Activity{
private String client,notifica;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
client = getIntent().getStringExtra("client");
notifica = getIntent().getStringExtra("notifica");
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Notifica da "+client);
alertDialog.setMessage(notifica);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alertDialog.cancel();
}
});
alertDialog.setIcon(R.drawable.icon);
alertDialog.show();
}
}
这就是我从服务中调用此活动的方式
Notification notification = new Notification(R.drawable.icon, "Notifica da "+client, 10000);
notification.flags |=Notification.FLAG_AUTO_CANCEL;
CharSequence contentTitle = "Notifica da "+client;
CharSequence contentText = notifica;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.defaults |= Notification.DEFAULT_VIBRATE;
//Intent notificationIntent = new Intent(this,ActivityNotification.class);
Intent notificationIntent = new Intent();
notificationIntent.setClassName("package", "package.ActivityNotification");
notificationIntent.putExtra("client",client);
notificationIntent.putExtra("notifica",notifica);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,0);
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
mManager.notify(id, notification);
我该怎么办?你可以帮帮我吗?
答案 0 :(得分:0)
你似乎有大量的东西在那里开始从服务开始一项活动。你为什么不能这样做:
Intent intent = new Intent(getBaseContext(), SomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(intent);
答案 1 :(得分:0)
听起来您需要恢复当前在手机上的应用程序的历史记录堆栈。 ActivityManager
可以帮助您解决此问题。
价:
http://developer.android.com/reference/android/app/ActivityManager.html