1

I have three activities - activity A ,activity B ,activity C . Activity A is the launcher activity . From this activity , I go to activity B .

The definition of activity B and activity C is as follows :

public class B extends C 
public abstract class C extends BaseActivity

Now I want to do something in activity B after completion of some task in activity C . I have searched in the google and stackoverflow . This leads me to this answer.

But following the above answer the call of function stateChanged() takes a lot of time . Is there any faster way to do this ?

Christopher Marlowe
  • 2,098
  • 6
  • 38
  • 68

3 Answers3

1

Every B activity is a C activity. So if you define a method in C that is inherited i.e. the method is public or protected Or package-private with B in same package then override the method as following:

@Override 
protected void method (){
    super.method ();
    myTaskAfterSuperMethodReturns ();
}

If you are doing some async task better you define async task in class B.

Another approach is define doSomething in Class C as an obstract method and implement it in B. Call doSomething when your task is done. Making doSomething abstract will force B to implement it.

Birendra Singh
  • 842
  • 11
  • 19
0

you can use EventBus Library to fire the event in Activity B when the task done in Activity C

Mina Farid
  • 5,041
  • 4
  • 39
  • 46
-1

You can also access the method of MainActivity from another Activity like this:

MainActivity.class

private static MainActivity mInstance;

public static MainActivity getInstance(){
    return mInstance;
}

In Oncreate method initialize the instance

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mInstance = this;
}

creating method to use in next activity

@Override
public void showData(){
    //do something here
}

To access it just call from another activity

(MainActivity.getInstance()).showData()