如何在Android应用程序中调用ParsePush.SubscribeInBackground方法?

时间:2015-01-16 07:37:54

标签: android parse-platform

我在Android应用程序中使用Parse服务器。并且还使用解析推送服务。 我已经设置了

ParsePush.subscribeInBackground("ChannelName");

在我的应用程序类中。

当用户从应用设置中停用通知时,我正在使用

ParsePush.unSubscribeInBackground("ChannelName");

但问题是,我在我的应用程序类中调用了parse push subscribe方法,因此它再次在Installation表中设置“ChannelName”。

问题 - 我在哪里可以在我的Android应用程序中声明ParsePush.subscribeInBackground("ChannelName")方法?

我只想拨打ParsePush.subscribeInBackground("ChannelName")一次。当用户首次安装我的Android应用时。

提前致谢!

1 个答案:

答案 0 :(得分:1)

您也可以通过检查ParseInstallation来检索已订阅的频道列表。无需将其他数据持久保存到SharedPreferences。检查ParseInstallation以查看是否已订阅该频道,如果是,则不要重新订阅。

final ParseInstallation mInstall = ParseInstallation.getCurrentInstallation();
final List<String> mList = mInstall.getList("channels");

//there are no subscriptions listed on the parse installation
if( mList == null )
{
    //subscribe
}

else if ( !mList.contains("KEY") )
{
    //subscribe
}

你可以使用一个if语句,但是如果你不小心的话,可能很难阅读并在以后解密。

if( mList != null && !mList.contains("KEY") ) 
{
    //subscribe!!!
}