[Solved] How to finish an activity from an Adapter..?

I tried with passing context of activity into the adapter and then i tried context.finish(); But its giving me one error like The method finish() is undefined for the type Context

Enquirer: Noby


Solution #1:

type cast it with activity.

Respondent: Yashwanth Kumar

Solution #2:

Try with the following code:

public YourAdapterName(......,Context context){



And in your adapter getView()

btn.setOnClickListener(new Button.OnClickListener() {

    public void onClick(View v) {

Respondent: raul_zevahc

Solution #3:

Try passing your Activity as an activity parameter, then you’ll be able to call finish() on it. Hope this helps.

Respondent: Egor

Solution #4:

Code for this is ((Activity)context).finish();and complete code is

holder.cardUsers.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Intent intent1=new Intent(mcontext,AstroChatPanel.class);
Respondent: Pradeep Sheoran

Solution #5:

In adapter it will work

Respondent: yogesh mhetre

Solution #6:

For Kotlin code:

(context as Activity).finish()
Respondent: Rahul Khatri

Solution #7:

i have not used it but i hope it will work.
“this.recreate()” if you are want to reload it from within the activity.

if you want to reload it from Adapter then use:

Respondent: neens

Solution #8:

Typecast your activity name with context and finish activity

Respondent: Deep Adhia

Solution #9:

In your custom adapter try to call finish use below code

Respondent: Mani

Solution #10:

close Activity form Class Custom Adapter just in method

  public void onClick(View v) {
    Intent intent = new Intent(MyApplication.context, VaasetActivity.class);
Respondent: iman hoshmand

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy