I want to store a string value that is inside an if block and i want to access the value outside of it. Now i tried with this code but it is giving me error and app force closed by saying "Print ln needs a message". It is a broadcast receiver class and this code is in OnReceive method.
I tried with this code:
if (!available)
for (String key : contactNumber.keySet()) {
String msgSender = contactNumber.get(key);
extractedContact = Utilities.extractNumbers(key);
preferences = context.getSharedPreferences("progress",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("number", extractedContact);
editor.apply();
}
String showNumber = preferences.getString("number", "");
Toast.makeText(context, showNumber + "Hello", Toast.LENGTH_LONG).show();
Now I just want to store that extracted contact value in shared pref and then I am retrieving it outside an if Blocks but it is giving me error. Can anyone know whats the issue? How can i retrieve the stored value