I have two Activities which both share a toolbar component that
extends a linear layout, the toolbar looks like this:
public class Toolbar extends LinearLayout {
...
public Toolbar(final Context con, AttributeSet attrs) {
super(con, attrs);
setGravity(Gravity.BOTTOM);
....
TextView tab1 = (TextView) findViewById(R.id.tab1);
tab1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(con,
ShowDashboard.class);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
//con.startActivity(intent);
((Activity)con).finish();
((Activity)con).startActivity(intent);
}
});
TextView tab2 = (TextView) findViewById(R.id.tab2);
tab2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(con, ShowLog.class);
//con.startActivity(intent);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
((Activity)con).finish();
((Activity)con).startActivity(intent);
}
});
....
}
When I click on tab 1 it works fine, it launches an acitvity
containing a webview. Likewise, tab 2 launches another tab with a
webview. The issue comes when I click tab 1 again, it restarts the
activity from scratch. I would like it to restore the state of the
webview to where it was. I believe I need to store the webview state
somehow and then on startup detect a restart and restore the webview
through the savedInstanceState Bundle. The issue I have is that the
bundle is always null even if I save it in the onSaveInstanceState
method of tab 1.
Tab 1's code looks like this:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
if (savedInstanceState != null) {
final File f = new File(lCurrentPicture);
webview.restorePicture(savedInstanceState, f);
webview.restoreState(savedInstanceState);
f.delete();
SharedPreferences.Editor editor = settings.edit();
editor.remove("dashboardwebviewfile");
editor.commit();
} else {
webview.loadUrl("http://www.yahoo.com");
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
isSavedInstanceState = true;
Log.i("ShowDashboard", "onSaveInstanceState");
File mThumbnailDir = getDir("thumbnails", 0);
webview.saveState(outState);
final File f = new File(mThumbnailDir, webview.hashCode() +
"_pic.save");
boolean savedPic = webview.savePicture(outState, f);
Log.d("ShowDashboard", "savedPic:" + savedPic);
outState.putString("currentPicture", f.getPath());
}
Tab 2 looks similar, any help is appreciated. Thanks!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en