protected void doSomething(Context context, Intent intent) {
Class<? extends Activity> cls = getActivity(context, intent);
Intent activityIntent;
if (uriString != null) {
activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uriString));
} else {
activityIntent = new Intent(context, cls);
}
activityIntent.putExtras(intent.getExtras());
activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
/*
In order to remove dependency on android-support-library-v4
The reason why we differentiate between versions instead of just using context.startActivity
for all devices is because in API 11 the recommended conventions for app navigation using
the back key changed.
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(cls);
stackBuilder.addNextIntent(activityIntent);
stackBuilder.startActivities();
} else {
context.startActivity(activityIntent);
}
}