eBehbahani
eBehbahani

Reputation: 1564

Can you finish() an activity from an object?

I have a class that represents my activity and a have an object that look like

  public class main extends Activity{
  //Does stuff
  }

  public class Object{
  //I want to call finish() here
  }

Is there any way to do that?

Upvotes: 0

Views: 716

Answers (1)

JRL
JRL

Reputation: 77995

You can make Object have a constructor accepting an Activity parameter, and pass in your activity instance when you instantiate your Object class.

Example:

class MyObject {
    private Activity act;
    public Object(Activity act) { this.act = act;}

    public doStuff() {
        // do stuff
        act.finish();
    }
}

//usage in some code inside your activity:
MyObject obj = new MyObject(this);
obj->doStuff();

Upvotes: 1

Related Questions