I don't quite understand what you mean by "start"
In java, you either:
- Declare a
static field or method
- Create an instance of an object and use its
public fields and methods.
If you wish to just have one 'instance' of MainActivity, use a static method:
public static void startEmergencyMode() {
// Code here
}
Which you can call anywhere using MainActivity.startEmergencyMode().
Keep in mind that this static method can only access static fields and other static methods.
If you wish to create an instance of MainActivity, simply create one and call the method:
public void startEmergencyMode() {
// Code here
}
// Somewhere else
MainActivity activity = new MainActivity();
activity.startEmergencyMode();
If you don't understand the difference between a static and non static method or field, refer the answer on this thread: What does 'public static void' mean in Java?