@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) { NavUtils.navigateUpFromSameTask(this); } return true; default: return super.onOptionsItemSelected(item); } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) { NavUtils.navigateUpFromSameTask(this); } return true; default: return super.onOptionsItemSelected(item); } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(getActivity()) != null) { app.send(this, "Action", "Discard Todo"); makeResult(RESULT_CANCELED); NavUtils.navigateUpFromSameTask(getActivity()); } hideKeyboard(mToDoTextBodyEditText); return true; default: return super.onOptionsItemSelected(item); } }
/** * Obtain an {@link Intent} that will launch {@link Intent#ACTION_MAIN} with an explicit * target activity specified by sourceActivity's {@link #PARENT_ACTIVITY} <meta-data> * element in the application's manifest. * * @param sourceActivity Activity to fetch a parent intent for * @return a new Intent targeting the defined parent activity of sourceActivity */ public static Intent getParentActivityIntent(Activity sourceActivity) { String parentActivity = getParentActivityName(sourceActivity); if (parentActivity == null) return null; return new Intent(Intent.ACTION_MAIN).setClassName(sourceActivity, parentActivity); }
/** * Obtain an {@link Intent} that will launch {@link Intent#ACTION_MAIN} with an explicit * target activity specified by sourceActivityClass's {@link #PARENT_ACTIVITY} <meta-data> * element in the application's manifest. * * @param context Context for looking up the activity component for sourceActivityClass * @param sourceActivityClass {@link java.lang.Class} object for an Activity class * @return a new Intent targeting the defined parent activity of sourceActivity * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid */ public static Intent getParentActivityIntent(Context context, Class<?> sourceActivityClass) throws NameNotFoundException { String parentActivity = getParentActivityName(context, new ComponentName(context, sourceActivityClass)); if (parentActivity == null) return null; return new Intent(Intent.ACTION_MAIN).setClassName(context, parentActivity); }
/** * Obtain an {@link Intent} that will launch {@link Intent#ACTION_MAIN} with an explicit * target activity specified by sourceActivityClass's {@link #PARENT_ACTIVITY} <meta-data> * element in the application's manifest. * * @param context Context for looking up the activity component for the source activity * @param componentName ComponentName for the source Activity * @return a new Intent targeting the defined parent activity of sourceActivity * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid */ public static Intent getParentActivityIntent(Context context, ComponentName componentName) throws NameNotFoundException { String parentActivity = getParentActivityName(context, componentName); if (parentActivity == null) return null; if (parentActivity.charAt(0) == '.') { parentActivity = context.getPackageName() + parentActivity; } return new Intent(Intent.ACTION_MAIN).setClassName(context, parentActivity); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()){ case android.R.id.home: if(NavUtils.getParentActivityName(this)!=null){ NavUtils.navigateUpFromSameTask(this); } return true; default: return super.onOptionsItemSelected(item); } } }
@Override public Intent getParentActivityIntent(Activity activity) { String parentName = NavUtils.getParentActivityName(activity); if (parentName == null) return null; // If the parent itself has no parent, generate a main activity intent. final ComponentName target = new ComponentName(activity, parentName); try { final String grandparent = NavUtils.getParentActivityName(activity, target); final Intent parentIntent = grandparent == null ? IntentCompat.makeMainActivity(target) : new Intent().setComponent(target); return parentIntent; } catch (NameNotFoundException e) { Log.e(TAG, "getParentActivityIntent: bad parentActivityName '" + parentName + "' in manifest"); return null; } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case android.R.id.home: if(NavUtils.getParentActivityName(this)!=null){ NavUtils.navigateUpFromSameTask(this); } return true; default: return super.onOptionsItemSelected(item); } } }
/** * Obtain an {@link Intent} that will launch an explicit target activity * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} <meta-data> * element in the application's manifest. * * @param context Context for looking up the activity component for sourceActivityClass * @param sourceActivityClass {@link java.lang.Class} object for an Activity class * @return a new Intent targeting the defined parent activity of sourceActivity * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid */ public static Intent getParentActivityIntent(Context context, Class<?> sourceActivityClass) throws NameNotFoundException { String parentActivity = getParentActivityName(context, new ComponentName(context, sourceActivityClass)); if (parentActivity == null) return null; // If the parent itself has no parent, generate a main activity intent. final ComponentName target = new ComponentName(context, parentActivity); final String grandparent = getParentActivityName(context, target); final Intent parentIntent = grandparent == null ? IntentCompat.makeMainActivity(target) : new Intent().setComponent(target); return parentIntent; }
/** * Return the fully qualified class name of sourceActivity's parent activity as specified by * a {@link #PARENT_ACTIVITY} <meta-data> element within the activity element in * the application's manifest. * * @param sourceActivity Activity to fetch a parent class name for * @return The fully qualified class name of sourceActivity's parent activity or null if * it was not specified */ public static String getParentActivityName(Activity sourceActivity) { try { return getParentActivityName(sourceActivity, sourceActivity.getComponentName()); } catch (NameNotFoundException e) { // Component name of supplied activity does not exist...? throw new IllegalArgumentException(e); } } /**
/** * Return the fully qualified class name of sourceActivity's parent activity as specified by * a {@link #PARENT_ACTIVITY} <meta-data> element within the activity element in * the application's manifest. * * @param sourceActivity Activity to fetch a parent class name for * @return The fully qualified class name of sourceActivity's parent activity or null if * it was not specified */ @Nullable public static String getParentActivityName(Activity sourceActivity) { try { return getParentActivityName(sourceActivity, sourceActivity.getComponentName()); } catch (NameNotFoundException e) { // Component name of supplied activity does not exist...? throw new IllegalArgumentException(e); } } /**
/** * Obtain an {@link Intent} that will launch an explicit target activity * specified by sourceActivityClass's {@link #PARENT_ACTIVITY} <meta-data> * element in the application's manifest. * * @param context Context for looking up the activity component for the source activity * @param componentName ComponentName for the source Activity * @return a new Intent targeting the defined parent activity of sourceActivity * @throws NameNotFoundException if the ComponentName for sourceActivityClass is invalid */ public static Intent getParentActivityIntent(Context context, ComponentName componentName) throws NameNotFoundException { String parentActivity = getParentActivityName(context, componentName); if (parentActivity == null) return null; // If the parent itself has no parent, generate a main activity intent. final ComponentName target = new ComponentName( componentName.getPackageName(), parentActivity); final String grandparent = getParentActivityName(context, target); final Intent parentIntent = grandparent == null ? IntentCompat.makeMainActivity(target) : new Intent().setComponent(target); return parentIntent; }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case android.R.id.home: if(NavUtils.getParentActivityName(this)!=null){ app.send(this, "Action", "Discard Todo"); makeResult(RESULT_CANCELED); NavUtils.navigateUpFromSameTask(this); } hideKeyboard(mToDoTextBodyEditText); return true; default: return super.onOptionsItemSelected(item); } }