How to work with onBackPresed Button in Android? -


i have 2 activities 'a' , 'b' in android application.

1) first time i'm going activity 'b' 'a'

2) in activity 'b' have 2 list-view , whenever perform onitemclicklistener of both list-view have store boolean values in preferences.

3) after when want go activity 'a' , want top retrieve preferences values in activity 'a'.

i have tried lot of not work

here code in activity 'a' in oncreate() method

      booleanvalue_one = sharedpreferences.getboolean("listview_event_one", false);       booleanvalue_two = sharedpreferences.getboolean("listview_event_two", false);        log.e("", "booleanvalue_one=" + booleanvalue_one + " booleanvalue_two=" + booleanvalue_two + " booleanvalue_three = " + booleanvalue_three); 

activity 'b' onbackpressed() code

@override     public void onbackpressed() {         super.onbackpressed();         intent = new intent(b.this, a.class);         startactivity(a);         overridependingtransition(r.anim.slide_in_bottom, r.anim.slide_out_bottom);     } 

can me how update previous activity 'a' onbackpressed() of activity 'b'

thanks in advance.

try onresume()

kill activity b on pressed.

@override public void onbackpressed() {     super.onbackpressed();     finish } 

and on resume on activity a

  @override    public void onresume() {     super.onresume();       booleanvalue_one = sharedpreferences.getboolean("listview_event_one", false);       booleanvalue_two = sharedpreferences.getboolean("listview_event_two", false);        log.e("", "booleanvalue_one=" + booleanvalue_one + " booleanvalue_two=" + booleanvalue_two + " booleanvalue_three = " + booleanvalue_three);   } 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -