I created an application which gets values from previous activity as extras and uses that values in that activity. And the values are then sent to another activity. But when I returned back from the moving activity to previous activity the extra values are becoming null.
For example, I get Values from Activity A to Activity B (some id and image id etc) Now, I sent that values to Activity C as Intent extras. Here in Activity C, I get the values (Initial Case)! Now when I press back to Activity B and Again moved to Activity C, I am not getting the values(some id and image id etc) in Activity C. This Happens in Marshmallow only. In Activity C name is getting from Server in Activity B and is Moved accordingly! This is working perfectly till lollipop! But this happens in Marshmallow!
My Activity B Fetchservices (Here it moves to another Activity code is:
public void fetchServices(){
mProgressBar.setVisibility(View.VISIBLE);
String android_id = Settings.Secure.getString(getContentResolver(),
Settings.Secure.ANDROID_ID);
String userid = prefs.getString("userId","0");
Log.e("USERID",userid);
Log.e("URL TOP UP", Constants.BASE_URL_SERVICE_LIST+"?deviceid="+android_id+"&userid="+userid +"&country="+countryname+"&countryid="+countryid);
RestClientHelper.getInstance().get(Constants.BASE_URL_SERVICE_LIST+"?deviceid="+android_id+"&userid="+userid+"&country="+countryname+"&countryid="+countryid, new RestClientHelper.RestClientListener() {
@Override
public void onSuccess(String response) {
Log.e("Resposnse",response);
mProgressBar.setVisibility(View.GONE);
parseResult(response);
mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Get item at position
GridItem item = (GridItem) parent.getItemAtPosition(position);
String myactivity = "com.mobeeloadpartner."+item.getGlobalActivity();
if(item.getGlobalActivity().equals("0") || item.getGlobalActivity() == null || ("").equals(item.getGlobalActivity())){
activity = Constants.getActivityClass("ComingSoon");
}
else{
activity = Constants.getActivityClass(item.getGlobalActivity());
}
Intent intent = new Intent(GlobalActivity.this, activity);
Log.e("Activity",item.getGlobalActivity());
intent.putExtra("country", countryname);
intent.putExtra("countryid", countryid);
intent.putExtra("countrycode", countrycode);
intent.putExtra("title", item.getTitle());
intent.putExtra("image", item.getImage());
intent.putExtra("serviceid", item.getServiceId());
//Start details activity
startActivity(intent);
}
});
}
@Override
public void onError(String error) {
}
});
}
Activity C onCreate Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Fabric.with(this, new Crashlytics());
setContentView(R.layout.international_topup);
toolbar = (Toolbar) findViewById(R.id.tool_bar); // Attaching the layout to the toolbar object
setSupportActionBar(toolbar);
prefs = new PreferenceHelper(InternationalTopup.this);
loading = (CircleProgressBar) findViewById(R.id.loading);
check = new CheckInterNetConnection(InternationalTopup.this);
mGridView = (GridView) findViewById(R.id.gridView);
loading.setVisibility(View.INVISIBLE);
//this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mGridData = new ArrayList<>();
mGridAdapter = new EloadGridViewAdapter(this, R.layout.grid_eload_amount, mGridData);
mGridView.setAdapter(mGridAdapter);
pd = new ProgressDialog(InternationalTopup.this);
isInternetPresent = check.isConnectingToInternet();
popup = (LinearLayout) findViewById(R.id.popup);
maintable = (TableLayout)findViewById(R.id.maintable);
tl = (TableLayout) findViewById(R.id.maintable);
noOps = (RelativeLayout) findViewById(R.id.noOps);
if (savedInstanceState == null) {
Bundle extras = getIntent().getExtras();
if(extras == null) {
countryname =null;
countryid = null;
countrycode = null;
} else {
countryname= extras.getString("country");
countryid= extras.getString("countryid");
countrycode= extras.getString("countrycode");
}
} else {
countryname= (String) savedInstanceState.getSerializable("country");
countryid= (String) savedInstanceState.getSerializable("countryid");
countrycode = (String) savedInstanceState.getSerializable("countrycode");
}
opimage = (ImageView)findViewById(R.id.opimage);
try {
countryid = countryid.toLowerCase();
}
catch(Exception e){
countryid = "0";
}
Picasso.with(getApplicationContext()).load(Constants.URL+"/app/countries/png250px/"+countryid+".png").fit().error(R.drawable.mobeeloadicon).into(opimage);
amount = (EditText)findViewById(R.id.amount);
amount.setText("0");
EditText mytext = (EditText)findViewById(R.id.phonenumber);
// mytext.setText(countrycode);
EditText code = (EditText)findViewById(R.id.code);
code.setText(countrycode);
code.setKeyListener(null);
mytext.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
operatorName = "Auto Fetch";
mGridAdapter.clear();
}
});
amount.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
}
public void onTextChanged(CharSequence s, int start,
int before, int count) {
localValue = "";
}
});
TextView countryName = (TextView)findViewById(R.id.countryname);
countryName.setText(countryname);
//amount.setEnabled(false);
if (isInternetPresent) {
} else {
Constants.showAlert(InternationalTopup.this,"Please check your internet connection and try again");
// SnackbarManager.show(Snackbar.with(InternationalTopup.this).text("Please check your internet connection and try again"));
}
}
Please help to sought out this issue!
Yeah!! That was a silly mistake! In developer option, there was an option to remove activity data when moving to activities! It was ON somehow! Keep it OFF!