1package ${packageName}; 2 3import android.content.Intent; 4import android.os.Bundle; 5import android.support.v4.app.FragmentActivity; 6import android.support.v4.app.NavUtils; 7import android.view.MenuItem; 8 9/** 10 * An activity representing a single ${objectKind} detail screen. This 11 * activity is only used on handset devices. On tablet-size devices, 12 * item details are presented side-by-side with a list of items 13 * in a {@link ${CollectionName}Activity}. 14 * <p> 15 * This activity is mostly just a 'shell' activity containing nothing 16 * more than a {@link ${DetailName}Fragment}. 17 */ 18public class ${DetailName}Activity extends FragmentActivity { 19 20 @Override 21 protected void onCreate(Bundle savedInstanceState) { 22 super.onCreate(savedInstanceState); 23 setContentView(R.layout.activity_${detail_name}); 24 25 // Show the Up button in the action bar. 26 getActionBar().setDisplayHomeAsUpEnabled(true); 27 28 // savedInstanceState is non-null when there is fragment state 29 // saved from previous configurations of this activity 30 // (e.g. when rotating the screen from portrait to landscape). 31 // In this case, the fragment will automatically be re-added 32 // to its container so we don't need to manually add it. 33 // For more information, see the Fragments API guide at: 34 // 35 // http://developer.android.com/guide/components/fragments.html 36 // 37 if (savedInstanceState == null) { 38 // Create the detail fragment and add it to the activity 39 // using a fragment transaction. 40 Bundle arguments = new Bundle(); 41 arguments.putString(${DetailName}Fragment.ARG_ITEM_ID, 42 getIntent().getStringExtra(${DetailName}Fragment.ARG_ITEM_ID)); 43 ${DetailName}Fragment fragment = new ${DetailName}Fragment(); 44 fragment.setArguments(arguments); 45 getSupportFragmentManager().beginTransaction() 46 .add(R.id.${detail_name}_container, fragment) 47 .commit(); 48 } 49 } 50 51 @Override 52 public boolean onOptionsItemSelected(MenuItem item) { 53 switch (item.getItemId()) { 54 case android.R.id.home: 55 // This ID represents the Home or Up button. In the case of this 56 // activity, the Up button is shown. Use NavUtils to allow users 57 // to navigate up one level in the application structure. For 58 // more details, see the Navigation pattern on Android Design: 59 // 60 // http://developer.android.com/design/patterns/navigation.html#up-vs-back 61 // 62 NavUtils.navigateUpTo(this, new Intent(this, ${CollectionName}Activity.class)); 63 return true; 64 } 65 return super.onOptionsItemSelected(item); 66 } 67} 68