android - How to send string from one activity to another? -


so have string in activity2

    string message = string.format( "current location \n longitude: %1$s \n latitude: %2$s", lat, lng);  

i want insert string text field in activity1. how can that? thank in advance.

you can use intents, messages sent between activities. in intent can put sort of data, string, int, etc.

in case, in activity2, before going activity1, store string message way :

intent intent = new intent(activity2.this, activity1.class); intent.putextra("message", message); startactivity(intent); 

in activity1, in oncreate(), can string message retrieving bundle (which contains messages sent calling activity) , call getstring() on :

bundle bundle = getintent().getextras(); string message = bundle.getstring("message"); 

then can set text in textview:

textview txtview = (textview) findviewbyid(r.id.your_resource_textview);     txtview.settext(message); 

hope helps !


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -