Reputation: 1
I have one main activity. It start another sub activities as Tab. On closing sub activities memory isn't released using by sub tab. Memory increases every time on opening other tabs.
After some time my application get crashed:
public class Main extends Activity {
public static Activity activity;
private Bundle saveInstance;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.activity = this;
this.saveInstance = savedInstanceState;
Application app = Application.getSharedInstance();
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
public void onBackPressed()
{
// super.onBackPressed();
AlertUtills.showQuitDialog(Main.this);
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
final TabHost tabHost = (TabHost) this
.findViewById(android.R.id.tabhost);
LocalActivityManager mLocalActivityManager = new LocalActivityManager(
this, false);
mLocalActivityManager.dispatchCreate(saveInstance);
tabHost.setup(mLocalActivityManager);
switch (item.getItemId())
{
case R.id.create_new:
{
if (CommonUtilities.isTabNotExist(tabHost, "NewProject"))
{
TabSpec spec2 = tabHost.newTabSpec("NewProject");
Intent in = new Intent(this, Activity_cretateNew.class);
in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
spec2.setContent(in);
spec2.setIndicator("New Project");
tabHost.addTab(spec2);
tabHost.setCurrentTabByTag("NewProject");
}
tabHost.setCurrentTabByTag("NewProject");
}
break;
case R.id.open:
{
OpenDialog dialog = new OpenDialog(this, "Open Project", false,
OpenDialogType.CORELOG_OPEN);
dialog.Show();
}
break;
case R.id.menu_exit:
onBackPressed();
break;
case R.id.import_las:
{
if (isCurrentProjectExist())
{
if (CommonUtilities.isTabNotExist(tabHost, "ImportLas"))
{
TabSpec spec2 = tabHost.newTabSpec("ImportLas");
Intent in = new Intent(this, LASImportWizard.class);
spec2.setContent(in);
spec2.setIndicator("Import Las");
tabHost.addTab(spec2);
}
tabHost.setCurrentTabByTag("ImportLas");
}
}
break;
case R.id.import_coredata:
{
if (isCurrentProjectExist())
{
if (CommonUtilities.isTabNotExist(tabHost, "coredata"))
{
TabSpec spec2 = tabHost.newTabSpec("coredata");
Intent in = new Intent(Main.this,
CoreDataImportWizard.class);
spec2.setContent(in);
spec2.setIndicator("Core Data Import");
tabHost.addTab(spec2);
}
tabHost.setCurrentTabByTag("coredata");
}
}
break;
case R.id.list_Data:
{
if (isProjectHasWell())
{
if (CommonUtilities.isTabNotExist(tabHost, "ListData"))
{
TabSpec spec1 = tabHost.newTabSpec("ListData");
Intent in = new Intent(Main.this, ListDataWindow.class);
// in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
spec1.setContent(in);
spec1.setIndicator("List Data");
tabHost.addTab(spec1);
}
tabHost.setCurrentTabByTag("ListData");
}
}
break;
case R.id.basemap:
{
if (isCurrentProjectExist())
{
if (CommonUtilities.isTabNotExist(tabHost, "BaseMap"))
{
TabSpec spec2 = tabHost.newTabSpec("BaseMap");
Intent inBasemap = new Intent(Main.this, Basemap.class);
spec2.setContent(inBasemap);
spec2.setIndicator("Base Map");
tabHost.addTab(spec2);
}
tabHost.setCurrentTabByTag("BaseMap");
}
}
break;
case R.id.logPlot:
{
if (isProjectHasWell())
{
if (CommonUtilities.isTabNotExist(tabHost, "LogPlot"))
{
TabSpec spec2 = tabHost.newTabSpec("LogPlot");
Intent intentLogPlot = new Intent(Main.this,
Logplot_Activity.class);
spec2.setContent(intentLogPlot);
spec2.setIndicator("Log Plot");
tabHost.addTab(spec2);
}
tabHost.setCurrentTabByTag("LogPlot");
}
}
break;
case R.id.show_hide_project_explorer:
{
FrameLayout frameLayout = (FrameLayout) activity
.findViewById(R.id.explorerFrame);
if (item.isChecked() == true)
{
item.setChecked(false);
frameLayout.setVisibility(View.GONE);
}
else
{
item.setChecked(true);
frameLayout.setVisibility(View.VISIBLE);
}
break;
}
}
return true;
}
private boolean isCurrentProjectExist()
{
return Application.getSharedInstance().getCurrentProject() == null ? false
: true;
}
private boolean isProjectHasWell()
{
return isCurrentProjectExist()
&& Application.getSharedInstance().getCurrentProject()
.getAllWells().length != 0 ? true : false;
}
public static Activity getMainActivity()
{
return activity;
}
}
Upvotes: 0
Views: 131
Reputation: 93542
Run hprof or another similar profiler. If this is happening, the number of objects of your tab activites will increase. See whats holding onto references to them, and then fix them so they don't.
Its kind of hard to debug this kind of thing without those hprofs.
Upvotes: 1