I would not recommend you to create Activity for each of your game level. Would be better to create some Controller that will initializate you game levels in one Activity. And of cource it must have some methods to clear memmory from last stage, something like this :
class StageManager
{
public Stage curStage;
public initStage(Stage stage)
{
//init stage here
curStage = stage;
stage.init();
}
public clearStage()
{
//do some clearing staff
curStage .clear();
}
}
abstract class Stage
{
public abstract init();
public abstract clear();
}
abstract class FirstStage extends Stage
{
//....
}
abstract class SecondStage extends Stage
{
//....
}
In Activity :
StageManager stageManager = new StageManager();
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.your_view);
stageManager.init(new FirstStage());
}
@Override
public void onClick(View theView)
{
int id = theView.getId();
if (id == R.id.btnNextLevel) {
stageManager.clear();
stageManager.init(new SecondStage());
}
}
Instead of your custom manager, you can use fragmets :
In both ways - fragments or yout own manager you will seperate different stages logic to different classes.
Youd don't need to create another Activity to seperate yours 1000+ lines code. Just use one of Stage or Stratagy desing patters.
And if you still want to use Activities just do something like this :
Intent myIntent = new Intent(getBaseContext(), Level3.class);
startActivity(myIntent);
finish();
and in onDestroy() :
@Override
protected void onDestroy()
{
//here you must clear all data that were used in this Stage (Activity) like this :
clearMemmory();
super.onDestroy();
}
private void clearMemmory()
{
if(stageData!=null)
{
stageData.clear();
stageData =null;
}
}
or clear memmory directly before opening another Stage, something like :
clearMemmory();
Intent myIntent = new Intent(getBaseContext(), Level3.class);
startActivity(myIntent);
finish();
Best wishes.