I have MainActivity which is an Activity and other class(which is a simple java class), we'll call it "SimpleClass".
Now I want to run from that class the command startActivityForResult
.
I though that I could pass that class (SimpleClass), using only MainActivity's context, but the problem is that we can't run context.startActivityForResult(...);
.
So, the only way making SimpleClass to use startActivityForResult
, is to pass the reference of MainActivity as an Activity variable to the SimpleClass.
Something like that:
Inside the MainActivity class I created the instance of SimpleClass like this way:
SimpleClass simpleClass = new SimpleClass(MainActivity.this);
Now, this is how SimpleClass looks like:
public Class SimpleClass {
Activity myMainActivity;
public SimpleClass(Activity mainActivity) {
super();
this.myMainActivity=mainActivity;
}
....
public void someMethod(...) {
myMainActivity.startActivityForResult(...);
}
}
Now it's working, but isn't there a proper way of doing this? I am afraid I could have some memory leaks in the future.