Use of finish() in android activity

by Tuesday, April 08, 2014 0 comments
Intro:
finish() it lets system to know that the developer wants the Activity to be finish, after finish it calls ondestroy() 

ondestroy() is for final cleanup ie.
  • closing open connections,readers,writers
  • dismiss any dialog the activity was running
  • close any cursors the activity was running

finish current activity:
To finish current activity use finish() in Intent.
 Intent intent = new Intent(FirstActivity.this, SecondActivity.Class);  
 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);  
 startActivity(intent);  
 finish();   

finish firstactivity from secondactivity:
To finish any Activity from another Activity (ie.Firstactivity.class from SecondActivty.class)
FirstActivity.class
 public static Activity firstIntent;  
in onCreate() function
 firstIntent = this;  

SecondActivity.class
 firstIntent.finish();  

Now firstactivity.class will finished from secondactivity.class.

karthik nagarajan

Androider

Welcome to Android-Action Blog. I’m a normal guy, who is passionate about Mobile Coding. Here I am writing about Android. Happy learning

0 comments:

Post a Comment