package com.recruit.app.ui.common; import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.view.MenuItem; import com.recruit.app.ui.Injector; import com.recruit.app.ui.main.MainActivity; import butterknife.Views; import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP; import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP; /** * Base activity which does not use fragments. */ public abstract class AbstractActivity extends ActionBarActivity { @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); Injector.inject(this); } @Override public void setContentView(final int layoutResId) { super.setContentView(layoutResId); // Used to inject views with the Butterknife library Views.inject(this); } @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { // This is the home button in the top left corner of the screen. case android.R.id.home: // Don't call finish! Because activity could have been started by an // outside activity and the home button would not operated as expected! final Intent homeIntent = new Intent(this, MainActivity.class); homeIntent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP); startActivity(homeIntent); return true; default: return super.onOptionsItemSelected(item); } } }