I've 2 activities Acivity 1
and Activity 2
. I'm passing values from Activity 1
to Activity 2
. Code is given below:
Activity 1
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("accountName", hashMaps.get(i).get("accountNumber"));
intent.putExtra("accountNumber", hashMaps.get(i).get("accountName"));
}
Activity 2
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_expand_collapse);
Bundle b1 = getIntent().getExtras();
if (b1 != null) {
String accountName = b1.getString("accountName");
String accountNumber = b1.getString("accountNumber");
Log.d(Tag, "Values are " + accountName);
Log.d(Tag, "Values are " + accountNumber);
}
}
Here is the AsyncTask code:
private class getData extends AsyncTask<Void, Void, HashMap<String, String>> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(CardViewExpandCollapse.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected HashMap<String, String> doInBackground(Void... voids) {
HttpHandler httpHandler = new HttpHandler();
String s = httpHandler.makeServiceCall(mUrl);
Gson gson = new Gson();
AccountDetail[] accountDetails = gson.fromJson(s, AccountDetail[].class);
ArrayList<AccountDetail> details = new ArrayList<>(Arrays.asList(accountDetails));
HashMap<String, String> accDetails = new HashMap<>();
String address = details.get(0).getRow().getBillToAddress();
Double balance = details.get(0).getRow().getTotalAccountBalance();
Double invoices = details.get(0).getRow().getTotalOpenInvoicesValue();
Log.e(Tag, "Response from URL " + s);
accDetails.put("billToAddress", address);
accDetails.put("totalAccountBalance", balance + "\tUSD");
accDetails.put("totalOpenInvoicesValue", invoices + "\tUSD");
hashMap.add(accDetails); // size = 3
return accDetails;
}
@Override
protected void onPostExecute(HashMap<String, String> accDetails ) {
super.onPostExecute(accDetails );
if (pDialog.isShowing()) {
pDialog.dismiss();
}
/*accnumber = (TextView) findViewById(R.id.txt_acc_num1);
accname = (TextView) findViewById(R.id.txt_acc_name1);
address = (TextView) findViewById(R.id.txt_address1);
totalaccbal = (TextView) findViewById(R.id.txt_total_acc_bal_value1);
openinvoice = (TextView) findViewById(R.id.txt_open_invoices_value1);*/
Log.e(Tag, "Address is " + address);
// Log.e(Tag, "Balance is " + balance);
// Log.e(Tag, "Invoice is " + invoices);
/*I want values of getExtras() added to TextView here*/
address.setText(accDetails.get("billToAddress"));
totalaccbal.setText(accDetails.get("totalAccountBalance"));
openinvoice.setText(accDetails.get("totalOpenInvoicesValue"));
}
}
Above codes are working fine. There are some TextViews in Activity 2
. I want to put accountName
and accountNumber
in those TextViews in onPostExecute() method. How can I do that?
i.e., I want values of getExtras() to be added to TextView in onPostExecute()
method. How can I do that?