打算开始活动-但不要走在前面 [英] Intent to start activity - but don't bring to front

查看:64
本文介绍了打算开始活动-但不要走在前面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说明:

  • 活动 A (在后台)可见
  • 广播中接收了
  • 意图 I ,并将其传递给新的意图 I2 ,该新意图将用于开始活动 A .
  • 结果:如果活动不在背景中,请勿将活动放在最前面.
  • Activity A is visible (or in the background)
  • Intent I is received by a broadcast with valuable extras and then passes the extras to a new Intent I2 that will be used to start activity A.
  • Outcome: Do not bring activity to front if activity is in background.

代码:

Intent I2= new Intent(context, MyActivity.class); 
I2.putExtra(..
I2.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK); // | Intent.FLAG_ACTIVITY_NEW_TASK); 
context.startActivity(I2);

注意:我没有添加任何"android:taskAffinity"来表示..我以为你应该知道

Note: I added no "android:taskAffinity" to manifest.. i thought you should know

推荐答案

如果您希望活动处于后台,请在活动的oncreate中添加此行

if you want your activity to be in background add this line in the oncreate of activity

moveTaskToBack(true);

这篇关于打算开始活动-但不要走在前面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆