繁体   English   中英

从后台启动具有特定活动的应用

[英]launch app with specific activity from background

当应用程序处于后台时,我想从broadcastreceiver打开非启动器活动。 我尝试使用Intent,但仍仅打开启动器页面。 有没有办法打开不是启动程序活动的其他任何活动,仍然打开整个应用程序? 在下面的代码中,当接到来电时,我正在检查应用程序是否在后台,是否正在发送打开应用程序的意图。

 public class CallStateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if(NgnInviteEventArgs.ACTION_INVITE_EVENT.equals(action)){ NgnInviteEventArgs args = intent.getParcelableExtra(NgnEventArgs.EXTRA_EMBEDDED); if(args == null){ Log.d("DEBUG", "Invalid event args"); return; } NgnAVSession avSession = NgnAVSession.getSession(args.getSessionId()); if (avSession == null) { return; } final NgnInviteSession.InviteState callState = avSession.getState(); NgnEngine mEngine = NgnEngine.getInstance(); switch(callState){ case NONE: default: break; case INCOMING: Log.i("DEBUG", "Incoming call"); if (isAppForground(context)) { context.startActivity(new Intent(context,CallScreen.class)); mEngine.getSoundService().startRingTone(); } else { System.out.println("sammy_isINbackground"); // when App is in Background Intent it = new Intent(); it.setComponent(new ComponentName(context.getPackageName(), MainActivity.class.getName())); it.putExtra("from", "receiver"); intent.putExtra("incomingSessionID", avSession.getId()); it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(it); Intent in = new Intent("android.intent.category.DEFAULT"); in.setClassName("nits_33.sipcall.CallStateReceiver", "nits_33.sipcall.CallScreen"); in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(in); mEngine.getSoundService().startRingTone(); } //for Ringtone mEngine.getSoundService().startRingTone(); break; case INCALL: Log.i("DEBUG", "Call connected"); mEngine.getSoundService().stopRingTone(); break; case TERMINATED: Log.i("DEBUG", "Call terminated"); mEngine.getSoundService().stopRingTone(); mEngine.getSoundService().stopRingBackTone(); break; } } } public boolean isAppForground(Context mContext) { ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1); if (!tasks.isEmpty()) { ComponentName topActivity = tasks.get(0).topActivity; if (!topActivity.getPackageName().equals(mContext.getPackageName())) { return false; } } return true; } } 

 Intent in = new Intent("android.intent.category.DEFAULT");
                            in.putExtra("incomingSessionID", avSession.getId());
                            in.setComponent(new ComponentName(context.getPackageName(), IncomingCallActivity.class.getName()));
                            in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(in);

如果您根本不关心历史,请查看

意图。FLAG_ACTIVITY_CLEAR_TOP

尝试这个

Intent dialogIntent = new Intent(this, YourActivity.class);
        dialogIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(dialogIntent);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM