こんにちは、問題があります...文字列データ フォーム アクティビティをサービスに送信したいのですが、データを共有設定に保存しました.すべてが機能しており、データをサービス クラスに渡すことができます..しかし、問題は文字列を共有設定に変更してEclipseからプロジェクトを実行すると、問題は発生しませんが、デバイスまたはエミュレーターからアプリケーションを開き、文字列を変更します..その時間値はサービスで更新されませんクラス、サービスクラスでは古いデータを取得します。値を表示しているデバッグを行う場合は、デバイスで古い値を表示します。助けてください
This is the code i tried...
Activity class,From where i sent the value to to the service class using alarm manager
@Override
protected void onResume() {
super.onResume();
// Preference Satting
prefs = PreferenceManager
.getDefaultSharedPreferences(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
myIntent = new Intent(PZAlarmTTSActivity.this, TtsService.class);
passedText = prefs.getString("text", "<unset>");
//Log.i("passed Text :", passedText);
// Passing the value to the service
Bundle bundle = new Bundle();
bundle.putString("k_key", passedText);
myIntent.putExtras(bundle);
Log.i("key Data : ", passedText);
// Pending intent to launch when the alarm triggers
pendintIntent = PendingIntent.getService(PZAlarmTTSActivity.this, 0,
myIntent, 0);
// Sets alarm to trigger
alarmManager.set(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendintIntent);
}
Service class, where i want to receive the string value
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Toast.makeText(this, "service started", Toast.LENGTH_LONG).show();
Bundle bundle = intent.getExtras();
String data = bundle.getString("k_key"); // Here data is not updating in 2nd case
Log.i("From service class : ", data);
}