嗨朋友我有一个问题...我想将字符串数据表单活动发送到服务,并且我已将数据保存到共享首选项中..我的一切正常,我能够将数据传递给服务类..但问题是那,如果我将字符串更改为共享首选项并从 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);
}