Although we can achieve to create a new instance of Fragment, why we can't do the same process to Activity class?
Who knows how we can manage activity from this perspective?
Although we can achieve to create a new instance of Fragment, why we can't do the same process to Activity class?
Who knows how we can manage activity from this perspective?
Activity instances are always created by the Android system. This is because a lot of initializations have to be done for the activity to work.
To create a new activity you call startActivity
with an Intent
describing the activity to start.
Activity A should have a variable
static ActivityA activityA;
In onCreate state:
activityA = this;
and add this method:
public static ActivityA getInstance(){
return activityA;
}
In activity B, call
ActivityA.getInstance().myFunction();
In order to get more information please go through this documentation: