Load SharedPreferences In MainActivity And Update In An Secondary Activity
Good morning everyone, I'm having problems again in my proccess to create my first app. This time with the SharedPreferences file. I have 2 activities that must use the same Shared
Solution 1:
I think you are accessing the value of Shared Preferences in onCreate()
of first Activity. That will be your problem. Beacuse when you come back from second activity to first activity, your onCreate()
is not called, instead onResume()
is called. So the better thing to do is move the code where you access SharedPreferences
value to a seperate function and call this function in both onCreate()
and onResume()
.
for e.g.
public void getSharedPrefernces() {
m_DataPLC = getSharedPreferences("CFTPreferences",CONTEXT_IGNORE_SECURITY);
m_NewIpAddress = m_DataPLC.getString("newIpAddress", m_NewIpAddress);
}
Hope this Helps..!! Cheers...
Post a Comment for "Load SharedPreferences In MainActivity And Update In An Secondary Activity"