in my application i can set String to SharedPreferences
with this code:
SharedPreferences prefs = this.getSharedPreferences("com.example.app", getApplicationContext().MODE_PRIVATE);
prefs.edit().putString("last__id", mLastID).commit ();
and i can get this seved data from SharedPreferences
in service by :
SharedPreferences sharedPref = getSharedPreferences("com.example.app", getApplicationContext().MODE_PRIVATE);
firstID = sharedPref.getString("last__id", null);
now i dont have problem in this time, but after start activity by service and change last__id
, i can not get new commited value from service, you think whats my code problem, whats tip and tricks?
POST UPDATE:
after commenting H4SN on this topic i want to use Messenger:
i get this error now:
ir.tsms fatal error : println needs a message
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.e(Log.java:231)
pass data from Activity:
Handler myHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
Bundle Recevied = msg.getData();
String resp = Recevied.getString("Mkey");
}
};
Messenger messenger = new Messenger(myHandler);
Message msg = Message.obtain();
Bundle data = new Bundle();
data.putString("Mkey",mLastID);
msg.setData(data);
get data from Service:
Bundle data = new Bundle();
String firstID = data.getString("Mkey");