-2

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?

Tarlan Ahad
  • 370
  • 4
  • 15

2 Answers2

2

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.

Henry
  • 42,982
  • 7
  • 68
  • 84
  • To add more to this answer. Activity, Service, BroadcastReceiver and ContentProvider all are system components. Android OS is responsible for creating, managing and destroying the instance of them. – Rohit Singh Feb 11 '22 at 16:24
0

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:

Android Activity Documentation

Tarlan Ahad
  • 370
  • 4
  • 15