【问题标题】:How to call ParsePush.SubscribeInBackground method only Once in android application?如何仅在 android 应用程序中调用 ParsePush.SubscribeInBackground 方法一次?
【发布时间】:2015-01-16 07:37:53
【问题描述】:

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

ParsePush.subscribeInBackground("ChannelName");

在我的应用程序类中。

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

ParsePush.unSubscribeInBackground("ChannelName");

但问题是,我在我的应用程序类中调用了解析推送订阅方法,所以它再次在安装表中设置了“ChannelName”。

问题 - 在我的 android 应用中,我在哪里声明 ParsePush.subscribeInBackground("ChannelName") 方法?

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

提前致谢!

【问题讨论】:

标签: android parse-platform


【解决方案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!!!
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-19
    • 2012-04-14
    • 1970-01-01
    • 2015-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多