0

Android( 2.3 )の時刻、日付、タイムゾーンの変更で古い値を持ちたいと思います。

次のような放送受信機を使用しています。

     <receiver android:name=".broadcastreceiver.OnDateTimeChanged">
        <intent-filter>
            <action android:name="android.intent.action.DATE_CHANGED"/>
            <action android:name="android.intent.action.TIME_SET"/>
            <action android:name="android.intent.action.TIMEZONE_CHANGED"/>
        </intent-filter>
    </receiver>

Javaクラス内では、古い値が必要です:

public class OnDateTimeChanged extends BroadcastReceiver
{
 @Override
 public void onReceive(Context context, Intent intent)
 {
     // Do some work here
     Log.d("OnDateTimeChanged", "intent action:"+intent.getAction() + ", intent : "+intent);

 }
}

時間、タイムゾーン、日付の OLD 値を取得 (ログアウト) する方法はありますか?

ありがとう

4

1 に答える 1

1

古い値を与える関数を知らないので、これを行うことをお勧めします:

アプリの起動時に、時刻、タイムゾーン、日付の現在の値を取得し、変数に保存します。より簡単にするためのクラスを作成できます。次に、その変数をデータセットに保存して、任意のアクティビティで使用できるようにします (または、必要に応じて追加で解析します)。次に、値が変更されるたびに変数も変更します。お気に入り:

public class OnDateTimeChanged extends BroadcastReceiver
{
 @Override
   public void onReceive(Context context, Intent intent)
   {
      // TimeManager is the name I gave to the class I told you before
      TimeManager timeManager = Provider.dataset().timeManager();

      // ... 

      // Calculate the elapsed time between the two times, if you need
      // (I didn't test but I think this will work)
      Date oldDateTime = timeManager.getDateTime();
      timeManager.setElapsedTime(currentDateTime - oldDateTime);

      // ...

      // And then at the end save the current values again,
      // (in this case: the DateTime)
      timeManager.setDateTime(currentDateTime);
   }
}

これはあなたが必要とするものですか?それが役に立てば幸い。

于 2012-12-03T15:20:11.537 に答える