android - 收到远程通知时在后台运行该方法而不启动应用程序
问题描述
我需要android中的机制,比如ios中的静默通知,需要在后台运行方法而不在我们收到通知时启动应用程序,怎么做?
public void onMessageReceived(RemoteMessage remoteMessage) {
AsyncTaskExample asyncTask=new AsyncTaskExample();
asyncTask.execute("http://100:5000/api/v1/todos");
}
在前台它正在工作,在后台不工作甚至在 firebaseJson 中也包含数据
解决方案
不幸的是(或幸运的是),如今的 Android 严重限制了后台行为,尤其是网络调用。请参考https://developer.android.com/about/versions/oreo/background
如果您要执行一些长时间运行的任务或使用 JobScheduler/WorkManager,您可能应该启动前台服务。
希望这可以帮助!
推荐阅读
- python - Redhat python 跟踪
- codenameone - 即使我从 Eclipse Marketplace 安装了 6.0 版,也安装了代号 1.0 版
- mysql - mysqldump 命令显示空白
- java - 如何在产品有折扣元素更改时获取 Selenium 文本
- html - 如何更改日历的背景颜色?
- javascript - 防止 Firefox 使用 javascript 处理按键
- apache-spark - python - 如何在带有Python的Spark中使用批处理间隔为10秒的套接字文本流从静态文件中读取?
- reactjs - 无法执行 React 状态更新 - useEffect 问题 - React Native
- asp.net - AddIdentity 的替代品是什么
()..AddActiveDirectoryStores().AddDefaultTokenProviders(); - xamarin.forms - Xamarin.Forms IOS 禁用更改设备主题对 App 设计的影响