killing an activity in android
Since my class could not inherit Activi开发者_如何学Cty class, I used context.startActivity() to launch a new activity. In this type of launch, how can kill the launched activity.? How can i use finish() in this circumstance?
If you started a new activity to get some result then you should use startActivityForResult()
instead of startActivity()
.
and if you want to stop an activity after performing some necessary tasks then call finish()
at the end of the onCreate()
after performing everything necessary.
and if you have something else in your mind then let me know. I will try my level best to help you.
In this type of launch, how can kill the launched activity.?
You don't.
How can i use finish() in this circumstance?
You don't. One activity does not finish another activity in general.
May the very next statement is to kill it.
Since the new activity will not have been displayed by the time of "very next statement", then you should not have started it in the first place.
You have to just pass contex object from LAUNCHER activity's onCreate method.
You may use below code.
`public Class ABc{
Contex co;
ABc(Contex con){
co=con;
}
con.startActivity(intent);
}`
And onCreate
method create object of this ABc
class.
精彩评论