0

少し問題がありました。

私は素晴らしいAndroid用の実行中のアプリケーションを持っています。「cleanservice」を使用してアクションをBlockingQueueに保存し、サービスが実行されるたびに実行されます。これで、ユーザーがアプリを閉じたいときに問題が発生します。彼が閉鎖したいとき、私はインターネットを介してすべてのアクションを送信するために最後にもう一度サービスを実行させます。

しかし、インターネット接続が利用できない場合、キューに入れられたすべてのアクションが失われます。

送信できない場合に閉じるときに、これらのアクション(sharedpreferencesやfileなど)を保存する方法が必要です。また、アプリを再度開いたときに、送信する必要のある未実行のアクションがある場合はチェックできます。

私はこれをデータを保存するいくつかの方法で見つけまし。しかし、最善の方法は何ですか?

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();

}

4

1 に答える 1

0

SQLiteデータベースをセットアップし、それによってアクションを追跡できます。これにより、キューが廃止され、アプリが強制的に閉じられた場合に備えて、アクションは常に既に保存されます。

または、共有設定にシリアル化(JSON?)して保存するだけです。

于 2012-07-13T14:29:00.627 に答える