Created
September 6, 2016 18:33
-
-
Save px-amaac/49d7c803304a2356c67cab013d63ec95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ActivityB extends BaseActivity { | |
private static final String TAG = ActivityB.class.getSimpleName(); | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ActionBar actionBar = getSupportActionBar(); | |
if(actionBar != null) { | |
actionBar.setTitle(TAG); | |
} | |
if(mButtonB != null) { | |
mButtonB.setVisibility(View.VISIBLE); | |
mButtonB.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent activityCIntent = new Intent(ActivityB.this, ActivityC.class); | |
startActivity(activityCIntent); | |
} | |
}); | |
} | |
Intent intent = getIntent(); | |
int cActivityExtra; | |
cActivityExtra = intent.getIntExtra(ActivityC.ACTIVITY_C_EXTRA, 0); | |
if(cActivityExtra != 0 && mTextView != null) { | |
mTextView.setText("Extra is " + cActivityExtra); | |
} | |
int mainExtra; | |
mainExtra = intent.getIntExtra(MainActivity.MAIN_ACTIVITY_EXTRA, 0); | |
if(mainExtra != 0 && mTextView != null) { | |
mTextView.setText("Extra is " + mainExtra); | |
} | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
// Respond to the action bar's Up/Home button | |
case android.R.id.home: | |
NavUtils.navigateUpFromSameTask(this); | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ActivityC extends BaseActivity { | |
private static final String TAG = ActivityC.class.getSimpleName(); | |
public static final String ACTIVITY_C_EXTRA = TAG + "_activity_c"; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
ActionBar actionBar = getSupportActionBar(); | |
if(actionBar != null) { | |
actionBar.setTitle(TAG); | |
} | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
switch (item.getItemId()) { | |
// Respond to the action bar's Up/Home button | |
case android.R.id.home: | |
NavUtils.navigateUpFromSameTask(this); | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
package="com.allday.doubleacoding.upnav"> | |
<application | |
android:allowBackup="true" | |
android:icon="@mipmap/ic_launcher" | |
android:label="@string/app_name" | |
android:supportsRtl="true" | |
android:theme="@style/AppTheme"> | |
<activity android:name=".MainActivity"> | |
<intent-filter> | |
<action android:name="android.intent.action.MAIN" /> | |
<category android:name="android.intent.category.LAUNCHER" /> | |
</intent-filter> | |
</activity> | |
<activity android:name="com.allday.doubleacoding.upnav.ActivityB" | |
android:parentActivityName="com.allday.doubleacoding.upnav.MainActivity"> | |
<meta-data | |
android:name="android.support.PARENT_ACTIVITY" | |
android:value="com.allday.doubleacoding.upnav.MainActivity" /> | |
</activity> | |
<activity android:name="com.allday.doubleacoding.upnav.ActivityC" | |
android:parentActivityName="com.allday.doubleacoding.upnav.ActivityB"> | |
<meta-data | |
android:name="android.support.PARENT_ACTIVITY" | |
android:value="com.allday.doubleacoding.upnav.ActivityB" /> | |
</activity> | |
</application> | |
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseActivity extends AppCompatActivity { | |
protected TextView mTextView; | |
protected ActionBar mActionBar; | |
protected Button mButtonA; | |
protected Button mButtonB; | |
protected Button mButtonC; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
mTextView = (TextView) findViewById(R.id.textbox); | |
mActionBar = getSupportActionBar(); | |
mButtonA = (Button) findViewById(R.id.button_a); | |
mButtonB = (Button) findViewById(R.id.button_b); | |
mButtonC = (Button) findViewById(R.id.button_c); | |
if(mActionBar != null) { | |
mActionBar.setDisplayHomeAsUpEnabled(true); | |
mActionBar.setHomeButtonEnabled(true); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends BaseActivity { | |
private static final String TAG = MainActivity.class.getSimpleName(); | |
public static final String MAIN_ACTIVITY_EXTRA = TAG + "_main_activity_extra"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
mActionBar.setDisplayHomeAsUpEnabled(false); | |
mActionBar.setTitle(TAG); | |
if(mButtonA != null) { | |
mButtonA.setVisibility(View.VISIBLE); | |
mButtonA.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent activityBIntent = new Intent(MainActivity.this, ActivityB.class); | |
startActivity(activityBIntent); | |
} | |
}); | |
} | |
if(mButtonB != null) { | |
mButtonB.setVisibility(View.VISIBLE); | |
mButtonB.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent activityCIntent = new Intent(MainActivity.this, ActivityC.class); | |
startActivity(activityCIntent); | |
} | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment