1 // Copyright 2011 Google Inc. All Rights Reserved. 2 3 package com.example.android.hcgallery; 4 5 import android.app.Activity; 6 import android.os.Bundle; 7 8 /** This is a shell activity that hosts ContentFragment when the device screen 9 * is smaller than "large". 10 */ 11 public class ContentActivity extends Activity { 12 private int mThemeId = 0; 13 14 @Override onCreate(Bundle savedInstanceState)15 public void onCreate(Bundle savedInstanceState) { 16 super.onCreate(savedInstanceState); 17 18 Bundle extras = getIntent().getExtras(); 19 if (extras != null) { 20 // The activity theme is the only state data that the activity needs 21 // to restore. All info about the content displayed is managed by the fragment 22 mThemeId = extras.getInt("theme"); 23 } else if (savedInstanceState != null) { 24 // If there's no restore state, get the theme from the intent 25 mThemeId = savedInstanceState.getInt("theme"); 26 } 27 28 if (mThemeId != 0) { 29 setTheme(mThemeId); 30 } 31 32 setContentView(R.layout.content_activity); 33 34 if (extras != null) { 35 // Take the info from the intent and deliver it to the fragment so it can update 36 int category = extras.getInt("category"); 37 int position = extras.getInt("position"); 38 ContentFragment frag = (ContentFragment) getFragmentManager().findFragmentById(R.id.content_frag); 39 frag.updateContentAndRecycleBitmap(category, position); 40 } 41 } 42 43 @Override onSaveInstanceState(Bundle outState)44 protected void onSaveInstanceState(Bundle outState) { 45 super.onSaveInstanceState(outState); 46 outState.putInt("theme", mThemeId); 47 } 48 } 49