Thursday, March 27, 2014

Synchronization service on the use of context and activity to read sharedpreferences of


For example, I use the activity object mainactivity the context acquired sharedpreferences object and putString (context, "demo", "aaaa");

Then get sharedpreferences object with the service object myservice of context, getString (context, "demo", "");
Thus obtained is "aaaa", is correct, but I then modify the key to "demo" values ​​mainactivity, the change "bbbb"
Then again get in myservice the "demo" of the value of the key bit, but still "aaaa", meaning that data is not synchronized, but I used RE Manager to view the configuration file, the key is "demo" of the values ​​have changed "bbbb" a ....
After seeking help, and I modified the configuration file service, activity go read, or the original data, but with the RE Manager to view, modify indeed ah, the data did not sync it?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Is not no call to commit
Reply:
cited a floor guoyoulei520 reply:
is not no call to commit
called, feeling activity and service operations are not the same configuration files, and I in service in the configuration file for writing, but I went to see the RE configuration file, find service did not successfully modified. However, activity modification can be successful.

I finally used the intent parameter passing, passing parameters to obtain the onstart method inside.
Reply:
commit there is a return value, you can look at. true success is modified, false failure.
Reply:
I have encountered this problem before, back into sync with the data of the handler. If the landlord insists on using the service, it can be more convenient with BroadCast match, when activity in the data changes, with the broadcast distributed services.
Reply:
references, 4th Floor a394268045 reply:
have I encountered such a problem before, back into a synchronous data handler. If the landlord insists on using the service, it can be more convenient with BroadCast match, when activity in the data changes, with the broadcast distributed services.


Do you mean to let service also inherited BroadcastReceiver onReceive then update the data in it, a good idea
Reply:
There is such a thing? Been using sharedpreferences, temporarily not encountered this situation the landlord.
Reply:
references, 5th Floor a740169405 reply:
Quote: references to the 4th floor a394268045 reply:

I have encountered this problem before, back into sync with the data of the handler. If the landlord insists on using the service, it can be more convenient with BroadCast match, when activity in the data changes, with the broadcast distributed services.


Do you mean to let service also inherited BroadcastReceiver onReceive then update the data in it, a good idea

This is a method, but may cause a delay broadcast.
Reply:
reference to the 7th floor ameyume reply:
Quote: references, 5th Floor a740169405 reply:

Quote: references to the 4th floor a394268045 reply:

I have encountered this problem before, back into sync with the data of the handler. If the landlord insists on using the service, it can be more convenient with BroadCast match, when activity in the data changes, with the broadcast distributed services.


Do you mean to let service also inherited BroadcastReceiver onReceive then update the data in it, a good idea

This is a method, but may cause a delay broadcast.

java does not support multiple inheritance. . .
Reply:
reference to the 7th floor ameyume reply:
Quote: references, 5th Floor a740169405 reply:

Quote: references to the 4th floor a394268045 reply:

I have encountered this problem before, back into sync with the data of the handler. If the landlord insists on using the service, it can be more convenient with BroadCast match, when activity in the data changes, with the broadcast distributed services.


Do you mean to let service also inherited BroadcastReceiver onReceive then update the data in it, a good idea

This is a method, but may cause a delay broadcast.



reference to the 8th floor b87936260 reply:
Quote: references to the 7th floor ameyume reply:

Quote: references, 5th Floor a740169405 reply:

Quote: references to the 4th floor a394268045 reply:

I have encountered this problem before, back into sync with the data of the handler. If the landlord insists on using the service, it can be more convenient with BroadCast match, when activity in the data changes, with the broadcast distributed services.


Do you mean to let service also inherited BroadcastReceiver onReceive then update the data in it, a good idea

This is a method, but may cause a delay broadcast.

java does not support multiple inheritance. . .


reference to the 8th floor b87936260 reply:
Quote: references to the 7th floor ameyume reply:

Quote: references, 5th Floor a740169405 reply:

Quote: references to the 4th floor a394268045 reply:

I have encountered this problem before, back into sync with the data of the handler. If the landlord insists on using the service, it can be more convenient with BroadCast match, when activity in the data changes, with the broadcast distributed services.


Do you mean to let service also inherited BroadcastReceiver onReceive then update the data in it, a good idea

This is a method, but may cause a delay broadcast.

java does not support multiple inheritance. . .

Inheritance is the service did not say where sendBroadcast, and then process the data in onReceive () in
Reply:
I have encountered this problem before, but a little research found that, getSharedPreferences used when the mode is MODE_PRIVATE, this mode does not support data synchronization between the activity with the service. The mode changed MODE_MULTI_PROCESS, the activity can be resolved directly modify share data, service can be directly synchronized.
I do not know the landlord is not able to solve the problem
Reply:
reference to the 10th floor limaolinghu reply:
I also encountered this problem before, but a little research found that, getSharedPreferences used when the mode is MODE_PRIVATE, which kind of mode does not support data synchronization between the activity with the service. The mode changed MODE_MULTI_PROCESS, the activity can be resolved directly modify share data, service can be directly synchronized.
I do not know the landlord is not able to solve the problem


Mad pull cool hanging fried days

Good way

No comments:

Post a Comment