回到previous屏幕电视机活动后 [英] Returning to previous screen after receiver activity

查看:124
本文介绍了回到previous屏幕电视机活动后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有具有可以从一开始就被启动一个活性的应用
菜单和由广播接收器开始活动

I have a app that has a activity that can be started from the start menu and a activity that is started by a broadcast receiver.

现在开机,如果接收器被调用时,事件查看器活动
开始......支持此项活动的用户后,返回到previous
屏幕(可以是主屏幕或任何用户在做什么)......这是怎么了
应该的。

Now on boot , if the receiver is called , the "event viewer" activity is started...after backing out of this activity user returns to previous screen (could be homescreen or whatever user was doing) .. this is how it should be.

但是,如果我开始从主发射的主的活动,和preSS
home键回到家里screen..the问题开始。
现在如果接收机被称为事件查看器的活性被示出。
如果用户备份出来的事件查看器的活动(或我称之为结束()),它会显示主活动(背景仍在运行中),而不是用户在做previous的事情(如主屏幕)。

But if i start the "main" activity from the main launcher, and press the home button to go back to the home screen..the problem begins. Now if the receiver is called the "event viewer" activity is shown. if the user backs out of the "event viewer" activity (or i call finish() ) it will show the "main" activity(still running in background) instead of the previous thing the user was doing (like home screen).

这是不是我多么希望它it..because导致用户解雇后
日历事件(我的应用程序的目的)返回到如设置
从主应用程序。

This is not how i want it..because it causes users after dismissing a calendar event (the purpose of my app) to return to eg the settings from the main app..

如果我在打电话完成的onPause(),它工作确定...但是这是不一样
它应该工作。

If i call finish() in onpause , it works ok...but that is not the way it should work.

任何线索?

希望这个问题是清楚的,因为英语不是我的第一语言,我
发现很难解释的问题: - )

Hope the problem is clear , since english isn't my first language i found it hard to explain the problem :-)

谢谢..

推荐答案

在您的接收器,使用该标志 FLAG_ACTIVITY_NEW_TASK

In your receiver, use the flag FLAG_ACTIVITY_NEW_TASK

@Override
public void onReceive(Context context, Intent intent) {
    //... bla bla bla

    Intent in = new Intent(context, IndependentActivity.class);
    in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(in);

    //... bla bla bla
}

在您的清单中,为您提供IndependentActivity一个taskAffinity。

In your manifest, provide a taskAffinity for your IndependentActivity.

    <activity
        android:name=".IndependentActivity"
        android:excludeFromRecents="true"
        android:taskAffinity="com.example.independantactivty.ind" >
    </activity>

我从最近通话排除它但这是完全可选的。

I have excluded it from the Recents but that is totally optional.

这篇关于回到previous屏幕电视机活动后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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