0

在我的 Android 项目中,我介绍了服务 pushwoosh。在示例中,我在 onCreate 方法启动中看到了这一点:

//Register receivers for push notifications
registerReceivers();

//Create and start push manager
PushManager pushManager = PushManager.getInstance(this);

//Start push manager, this will count app open for Pushwoosh stats as well
try {
    pushManager.onStartup(this);
}
catch(Exception e)
{
    //push notifications are not available or AndroidManifest.xml is not configured properly
}
//Register for push!
pushManager.registerForPushNotifications();
String token= PushManager.getPushToken(this);

checkMessage(getIntent());

1)我想知道我是否应该在每次启动应用程序时都这样做,还是只在第一次启动时这样做。

2)什么是onResume方法和方法OnPause启动registerReceiver和unregisterReceivers?

4

1 回答 1

0

1.)根据谷歌的说法,他们建议在每次启动时注册设备,因为有时,设备注册 ID 可能会发生变化(如果有的话,您可以降低用户不愿意被取消注册并且不知道它的风险!)

2.) 至于 onResume 和 onPause,它们与应用程序的 savedInstanceState 相关。所以,onPause(当应用程序暂停时),你可能想做点什么。然后,onResume 会提醒应用程序应该进行什么活动,以便用户可以与之交互。他们真的要确保应用程序不会过早地终止它已经开始或打算在新活动出现时开始的活动。你可以在这里读更多关于它的内容:

http://developer.android.com/reference/android/app/Activity.html

于 2014-07-30T17:42:58.247 回答