我创建了一个应用程序,它从以前的活动中获取值作为附加值,并在该活动中使用该值。然后将这些值发送到另一个活动。但是当我从移动活动返回到前一个活动时,额外的值变为空。
例如,我从活动 A获取值到活动 B(一些 id 和图像 id 等)现在,我将这些值作为 Intent extras发送到活动 C。在Activity C中,我得到了值(初始情况)!现在,当我按回 Activity B并再次移至Activity C时,我没有在 Activity C 中获得值(一些 id 和图像 id 等)。这仅发生在棉花糖中。在活动 C中,名称从活动 B中的服务器获取并相应移动!直到棒棒糖为止,这一切都很好!但这发生在棉花糖!
我的活动 B Fetchservices(这里它移动到另一个活动代码是:
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 代码:
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"));
}
}
请帮忙找出这个问题!