0
我遇到了一些问题。在Android上保存未执行的网络操作
我有一个运行Android的应用程序,它很棒。 我使用“cleanservice”将操作存储在BlockingQueue中,然后在服务运行的每一分钟执行一次。 现在,当用户想要关闭应用程序时,就会出现问题。当他想关闭时,我最后一次运行该服务,通过互联网发送所有操作。
但是,当没有互联网连接可用时,我所有排队的操作都会丢失。
我需要一种方法来存储这些操作(如在sharedpreferences或文件或...)时,如果他们不能发送关闭。当我再次打开应用程序时,如果有未执行的操作需要发送,我可以尝试。我发现this有几种存储数据的方式。但是最好的方法是什么?
if(!finaltry)
processActionQueues(true, true);
else{
// We get here when we are logging off (shutting down) and our final try has failed to send the updates to the server
// We are going to save the actions so we can send them when we log on again
}
我的行为是在这个界面:
public interface IWebServiceAction {
/**
* Executes the action on the server.
* Here you would typically do an http request to the webservice
* @param ctx
* @return
* @throws IOException
* @throws AuthenticationException
*/
boolean execute(Context ctx) throws IOException, AuthenticationException;
/**
* Indicates whether this is an urgent action. If the action is
* to be executed by the CleanService then it will execute it
* immediately if the action is urgent.
* Default = false
* @return
*/
boolean isUrgent();
/**
* If the user needs to be logged into the system before we can
* execute the action then isPrivate is true.
* Public actions that can be executed regardless of login are for
* example the login action itself, or a check for updates.
* Default = true
* @return
*/
boolean isPrivate();
/**
* Indicates whether this action requires that all previous actions are
* executed before we begin executing this one
* @return
*/
boolean requiresQueueuToBeCompleted();
}
我与Json合作是的,所以我会给sharedPreferences一个尝试。 – Robin 2012-07-16 14:30:05