简体   繁体   English

在Android中管理后台服务和前台“首选项”活动的正确模型

[英]The right model to manage background service and foreground “Preferences” Activity in Android

I want to write an app which is consist on two major parts: 1. BroadcastReceiver that will intercept incoming SMS messages and act on them. 我想编写一个包含两个主要部分的应用程序:1. BroadcastReceiver,它将拦截传入的SMS消息并对其进行操作。 2. Activity with GUI to manage the user preferences that will define the behavior of the broadcast receiver upon new SMS. 2.使用GUI进行活动以管理用户首选项,这些首选项将定义新SMS时广播接收器的行为。

My questions are: 我的问题是:

  1. What is the right model in general to achieve my goal? 一般而言,什么是实现我的目标的正确模型? am i right in my assumption that i should use an activity for the "Preferences" and BroadcastReciever for the underlying service? 我以为我应该对“首选项”使用活动,对基础服务使用BroadcastReciever吗?
  2. How can save the user's preferences persistently (like in a file or something) and make them also accessible for the service to read them? 如何持久保存用户的首选项(如保存在文件或其他内容中),并使服务也可以访问它们以读取它们?
  3. How do i make it that the service will be launched at the device's startup? 我如何确保该服务将在设备启动时启动?

1 . 1。 you should use PreferenceActivity for setting and BroadcastReceiver for SMS monitoring. 您应该使用PreferenceActivity进行设置,并使用BroadcastReceiver进行SMS监视。 follow this link to use PreferenceActivity PreferenceActivity link 单击此链接以使用PreferenceActivity PreferenceActivity链接

2 . 2。 You can use SharedPreference to store your preference persistantly follow this link http://saigeethamn.blogspot.com/2009/10/shared-preferences-android-developer.html 您可以使用SharedPreference持久存储您的首选项,请访问此链接http://saigeethamn.blogspot.com/2009/10/shared-preferences-android-developer.html

3 . 3。 you don't need to start the Service here because BroadcastReceiver will go all stuff for you. 您无需在此处启动服务,因为BroadcastReceiver会帮您解决所有问题。 by the way Service can be started at Boot Time follow this link start service at boot time 顺便说一下,可以在启动时启动服务的方式在启动时遵循此链接启动服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM