如果一个应用程序是为了运行状态触发意图是什么? [英] Should an app be in running state in order to trigger intent?

查看:116
本文介绍了如果一个应用程序是为了运行状态触发意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的IntentReceiver当时间的变化来接收事件。这里的code:

I have a very simple IntentReceiver to receive event when time changes. Here's the code:

public class IntentRec extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.i("IntentRec", intent.getAction());
    }
}

<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
    <receiver android:name=".IntentRec">
        <intent-filter>
            <action android:name="android.intent.action.TIME_SET"/>
        </intent-filter>
    </receiver>
    <activity android:name="MyActivity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

不过,我收到意图应用程序运行时。但是,如果我关闭(使用强制关闭)的应用程序,的onReceive不叫。所以我的问题是,我收到意图监听器应用程序正在运行,只有当?我认为意图旨在运行目标监听器类,当应用程序没有运行。

However, I receive the intent while the application is running. But if I shutdown (using Force Close) the app, onReceive is not called. So my question is, do I receive intents only when listener app is running? I thought that intents was designed to run target listener class when the app was not running.

感谢

推荐答案

解决的办法很简单:停止点击强制关闭

The solution is simple: stop clicking Force Close.

在Android 3.1以上版本,强制关闭将在您的应用程序再次运行prevent任何东西,直到用户手动运行你的一个活动,还是其他什么东西(例如,第三方应用程序)启动您的应用程序。

On Android 3.1+, Force Close will prevent anything in your app from running again, until the user runs an activity of yours manually, or something else (e.g., third-party app) starts up your app.

更新

我怀疑你被这个词的多重含义混淆已停止。让我们穿行的过程中,避免了单词停止,看它是否有帮助。

I suspect that you are being confused by multiple meanings of the word "stopped". Let's walk through the process, avoiding the word "stopped", to see if it helps.

当你的应用程序在第一次安装在Android设备上,是众所周知的一些人视为snicklefritzed的状态。而应用程序是在这个snicklefritzed状态,没有明显注册广播接收器将工作。要移动应用了snicklefritzed状态,一些第三方的应用程序(如主屏幕发射器)必须明确要求来运行你的应用程序的东西(比如一个活动)。所以,事件的正常过程是用户下载你的应用程序,在启动器图标点击它,你的应用程序移动到正常状态,并从snickelfritzed状态了。而在正常状态,你的广播接收器将正常工作。

When your app is first installed on an Android device, is in a state known to some as "snicklefritzed". While the app is in this "snicklefritzed" state, no manifest-registered BroadcastReceiver will work. To move an app out of the "snicklefritzed" state, some third-party app (like the home screen launcher) must explicitly request to run something in your app (like an activity). So, the normal course of events is that the user downloads your app, clicks on the launcher icon for it, and your app is moved into the "normal" state and away from the "snickelfritzed" state. While in the "normal" state, your BroadcastReceiver will work fine.

让我们假设你的广播接收器 ACTION_BOOT_COMPLETED 播出。在snicklefritzed状态无关,与你的应用程序是presently运行与否 - 这只有在如果你的应用程序有曾经的运行或不依赖。因此,如果用户安装的应用程序,但您的应用程序,在做任何事情之前重新启动他们的电话你的 ACTION_BOOT_COMPLETED 接收器的的获得在开机时间控制。但是,如果用户运行的东西在你的应用程序,的然后的重新启动手机,您的接收器将接收 ACTION_BOOT_COMPLETED 播出正常。

Let's suppose that your BroadcastReceiver is for the ACTION_BOOT_COMPLETED broadcast. The "snicklefritzed" state has nothing to do with whether your app is presently running or not -- it is dependent only upon if your app has ever run or not. Hence, if the user installs your app, but reboots their phone before doing anything with your app, your ACTION_BOOT_COMPLETED receiver will not get control at boot time. If, however, the user runs something in your app, then reboots the phone, your receiver will receive the ACTION_BOOT_COMPLETED broadcast as normal.

通常,应用程序搬出snicklefritzed状态,并且永远不会返回到该状态。有一件事,将会的会导致应用程序被snicklefritzed又是,如果用户点击强制关闭了该应用程序的设置。在这里,用户是当然pressly的Andr​​oid告诉您的应用程序出现异常,直到该用户说,否则不应该再运行。如果,当然,用户再次启动你的活动,您将回到正常状态。

Normally, apps move out of the "snicklefritzed" state and never return to that state. One thing that will cause an app to be "snicklefritzed" again is if the user clicks on Force Close for this app in Settings. Here, the user is expressly telling Android that your app is misbehaving and should not run again until the user says otherwise. If, of course, the user launches your activity again, you move back to "normal" state.

这篇关于如果一个应用程序是为了运行状态触发意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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