android - Come back to the activity without creating a new one after onItemClick on a ListView -


i have option menu in app shows list of markers user added on map. markers represented using listview, , when user selects 1 of items of listview, want go (resume?) main activity passing marker position parameter, without creating new activity. possible? creating new activity when user clicks on item, possible come main activity?

code of markerslist activity:

mainlistview.setonitemclicklistener(new onitemclicklistener() {     public void onitemclick(adapterview<?> arg0, view v, int position, long id)     {             intent intent = new intent(getbasecontext(), mainactivity.class);         mymarkerobj marker = (mymarkerobj)table.get(position);         intent.putextra("position", marker.getid());         startactivity(intent);         finish();     } }); 

code of mainactivity:

 @override protected void onresume() {        intent intent = getintent();      if (intent != null) {          bundle bundle = intent.getextras();         if (bundle != null) {             int reportid = bundle.getint("position");             toast.maketext(getapplicationcontext(), integer.tostring(reportid), toast.length_short).show();               try {                 data.open();                } catch (exception e) {                     log.i("hello", "hello");                }                //get marker selected in listview             string position = data.getmarkerbyid(reportid);             //system.out.println(">>>>>>>>>>>>>>> position = " + position);          }     }     super.onresume(); } 

use startactivityforresult(intent,reqcode) instead of startactivity(intent).

first in first activity

intent i=new intent(mainactivity.this, markeractivity.class); startactivityforresult(i,1);  <-- 1 request code, can give anything. 

and on itemclick of second activity

 intent intent = getintent();     mymarkerobj marker = (mymarkerobj)table.get(position);     intent.putextra("position", marker.getid());    setresult(responsecode,intent);     finish(); 

and in

onactivityforresult of firstactivity

get value this

 protected void onactivityresult(int requestcode, int resultcode, intent data)      {      if(requestcode == 1 && resultcode == result_ok)         {         bundle bun=data.getextras();        int position= bun.getint("position");              }     } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -