Skip to content

Instantly share code, notes, and snippets.

@DevPicon
Created November 14, 2015 15:51
Show Gist options
  • Save DevPicon/f35afda5d2b9d28fa715 to your computer and use it in GitHub Desktop.
Save DevPicon/f35afda5d2b9d28fa715 to your computer and use it in GitHub Desktop.
Observemos estos tres activities, en un primer momento solo los dos primeros comparten la misma clase padre y cuentan con elementos comunes dentro de su función onCreate()
public class MainActivity extends AppCompatActivity implements PlaceListFragment.Callback {
private boolean mTwoPane = false;
private String LOG_TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (findViewById(R.id.place_detail_container) != null) {
mTwoPane = true;
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.place_detail_container, new PlaceDetailFragment())
.commit();
}
} else {
mTwoPane = false;
}
// Show home icon
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
PlaceSyncAdapter.initializeSyncAdapter(this);
}
public class PlaceDetailActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_place_detail);
if (savedInstanceState == null) {
long placeId = getIntent().getLongExtra(PlaceDetailFragment.PLACE_KEY, -1);
Bundle arguments = new Bundle();
arguments.putLong(PlaceDetailFragment.PLACE_KEY, placeId);
PlaceDetailFragment fragment = new PlaceDetailFragment();
fragment.setArguments(arguments);
getSupportFragmentManager().beginTransaction()
.add(R.id.place_detail_container, fragment)
.commit();
}
}
public class SettingsActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
//bindPreferenceSummaryToValue(findPreference(getString(R.string.pref_location_default)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment