简体   繁体   English

当应用程序不在屏幕顶部时保持活动

[英]Keep activity while the app is not on top of screen

I got a problem with multitasking, its probably a stupid question but after looking for hours an answer, i dont know how to do it everybody seems got that by default. 我遇到了多任务处理的问题,这可能是一个愚蠢的问题,但在找了几个小时的答案之后,我不知道怎么做,每个人似乎都默认了。

So my problem is I've two activities A (main) and B (conataing exoplayer), A--->B but when im on B and i press lock button or switch app: onPause is been called (normal) and onStop too, i reopen the app, and I'm back to A, the instance of B seem destroyed but the player still playing the audio. 所以我的问题是我有两个活动A(主要)和B(conataing exoplayer),A ---> B但是当我在B上我按下锁定按钮或切换app:onPause被称为(正常)和onStop也是,我重新打开应用程序,然后我回到A,B的实例似乎被破坏但玩家仍在播放音频。

What i would like to do is Keep B how it was or pause the audio/video on hold B, most important thing is to keep b on top and not go back to main (A). 我想做的是保持B它是如何或暂停音频/视频保持B,最重要的是保持b在顶部而不是回到主(A)。

Thanks for your help. 谢谢你的帮助。

Try to start your activity B with: 尝试使用以下内容开始您的活动B:

Intent intent = new Intent(this, ActivityB.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);

This will start ActivityB as a new task and destroy ActivityA, so returning to it should not be possible. 这将启动ActivityB作为新任务并销毁ActivityA,因此不应该返回它。 If you currently have some flags added to either ActivityA or B, they could also be interferencing with returning to desired activity after pressing home button. 如果您当前在ActivityA或B中添加了一些标记,则在按下主页按钮后,它们也可能会干扰返回所需的活动。

在AndroidManifest中,您可以使用元素内的“launchMode”属性来声明活动B的启动模式

<activity android:launchMode=”singleTask” />

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

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