Java Code Examples for android.app.Activity#getClass()
The following examples show how to use
android.app.Activity#getClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PuzzleActivity.java From EasyPhotos with Apache License 2.0 | 6 votes |
public static void startWithPhotos(Activity act, ArrayList<Photo> photos, int requestCode, boolean replaceCustom, @NonNull ImageEngine imageEngine) { if (null != toClass) { toClass.clear(); toClass = null; } if (Setting.imageEngine != imageEngine) { Setting.imageEngine = imageEngine; } Intent intent = new Intent(act, PuzzleActivity.class); intent.putExtra(Key.PUZZLE_FILE_IS_PHOTO, true); intent.putParcelableArrayListExtra(Key.PUZZLE_FILES, photos); if (replaceCustom) { toClass = new WeakReference<Class<? extends Activity>>(act.getClass()); } act.startActivityForResult(intent, requestCode); }
Example 2
Source File: EventTracker.java From foam with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Check for classes with @FoamDontTrack annotation. * @param activity Check if this activity should be tracked. * @return true if Activity does not have FoamDontTrack (on class on any of the methods) */ boolean shouldTrack(Activity activity) { if(wifiOnly && !utils.isOnWifi(context)){ return false; } else if(activity!=null){ Class<? extends Activity> clazz = activity.getClass(); if(clazz.isAnnotationPresent(FoamDontTrack.class)){ return false; } else { for (Method method : clazz.getMethods()) { if(method.isAnnotationPresent(FoamDontTrack.class)){ return false; } } } } return true; }
Example 3
Source File: SettingsFragment.java From prayer-times-android with Apache License 2.0 | 6 votes |
@Override public boolean onPreferenceChange(@NonNull Preference pref, Object newValue) { if ("language".equals(pref.getKey()) || "digits".equals(pref.getKey())) { if ("language".equals(pref.getKey())) Preferences.LANGUAGE.set((String) newValue); Activity act = getActivity(); act.finish(); Intent i = new Intent(act, act.getClass()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); act.startActivity(i); Answers.getInstance().logCustom(new CustomEvent("Language").putCustomAttribute("lang", (String) newValue)); } return true; }
Example 4
Source File: ActivityRecreationHelper.java From LocaleChanger with Apache License 2.0 | 6 votes |
/** * Helper method to recreate the Activity. This method should be called after a Locale change. * @param activity the Activity that will be recreated * @param animate a flag indicating if the recreation will be animated or not */ public static void recreate(Activity activity, boolean animate) { Intent restartIntent = new Intent(activity, activity.getClass()); Bundle extras = activity.getIntent().getExtras(); if (extras != null) { restartIntent.putExtras(extras); } if (animate) { ActivityCompat.startActivity( activity, restartIntent, ActivityOptionsCompat .makeCustomAnimation(activity, android.R.anim.fade_in, android.R.anim.fade_out) .toBundle() ); } else { activity.startActivity(restartIntent); activity.overridePendingTransition(0, 0); } activity.finish(); }
Example 5
Source File: DefaultAppLock.java From UltimateAndroid with Apache License 2.0 | 6 votes |
@Override public void onActivityResumed(Activity arg0) { if( arg0.getClass() == PasscodeUnlockActivity.class ) return; if( ( this.appLockDisabledActivities != null ) && Arrays.asList(this.appLockDisabledActivities).contains( arg0.getClass().getName() ) ) return; if(mustShowUnlockSceen()) { //uhhh ohhh! Intent i = new Intent(arg0.getApplicationContext(), PasscodeUnlockActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); arg0.getApplication().startActivity(i); return; } }
Example 6
Source File: LocalesUtils.java From rosetta with MIT License | 6 votes |
/** * Refreshing the application so no weired results occurred after changing the locale. */ static void refreshApplication(Activity activity) { Intent app = activity.getBaseContext().getPackageManager() .getLaunchIntentForPackage(activity.getBaseContext().getPackageName()); app.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); Intent current = new Intent(activity, activity.getClass()); sLogger.debug("Refreshing the application: " + activity.getBaseContext().getPackageName()); sLogger.debug("Finishing current activity."); activity.finish(); sLogger.debug("Start the application"); activity.startActivity(app); activity.startActivity(current); sLogger.debug("Application refreshed"); }
Example 7
Source File: PinActivity.java From budget-envelopes with GNU General Public License v3.0 | 6 votes |
public static boolean ensureUnlocked(Activity a) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(a.getApplicationContext()); boolean done = prefs.getString("com.notriddle.budget.pin", "").equals("") || prefs.getBoolean("com.notriddle.budget.unlocked", false); if (!done) { Intent i = new Intent(a, PinActivity.class); Intent j = new Intent(a.getApplicationContext(), a.getClass()); //j.setData(a.getIntent().getData()); //j.setAction(a.getIntent().getAction()); j.putExtras(a.getIntent()); PendingIntent pJ = PendingIntent.getActivity(a.getApplicationContext(), 0, j, PendingIntent.FLAG_UPDATE_CURRENT); Log.d("Budget", "pJ="+pJ); i.putExtra("com.notriddle.budget.NEXT_ACTIVITY", (Parcelable)pJ); a.startActivity(i); } else { notify(a); } return done; }
Example 8
Source File: DefaultAppLock.java From narrate-android with Apache License 2.0 | 6 votes |
@Override public void onActivityResumed(Activity arg0) { if( arg0.getClass() == PasscodeUnlockActivity.class ) return; if( ( this.appLockDisabledActivities != null ) && Arrays.asList(this.appLockDisabledActivities).contains( arg0.getClass().getName() ) ) return; if(mustShowUnlockSceen()) { //uhhh ohhh! Intent i = new Intent(arg0.getApplicationContext(), PasscodeUnlockActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); arg0.getApplication().startActivity(i); return; } }
Example 9
Source File: PassportConActivity.java From polling-station-app with GNU Lesser General Public License v3.0 | 6 votes |
/** * Setup the recognition of nfc tags when the activity is opened (foreground) * * @param activity The corresponding {@link Activity} requesting the foreground dispatch. * @param adapter The {@link NfcAdapter} used for the foreground dispatch. */ public static void setupForegroundDispatch(final Activity activity, NfcAdapter adapter) { final Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); final PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0); IntentFilter[] filters = new IntentFilter[1]; String[][] techList = new String[][]{}; // Filter for nfc tag discovery filters[0] = new IntentFilter(); filters[0].addAction(NfcAdapter.ACTION_TAG_DISCOVERED); filters[0].addCategory(Intent.CATEGORY_DEFAULT); adapter.enableForegroundDispatch(activity, pendingIntent, filters, techList); }
Example 10
Source File: ReflectorFactory.java From UltimateAndroid with Apache License 2.0 | 5 votes |
private static Reflector.ActionBarType searchForActivitySuperClass(Activity activity) { Class currentLevel = activity.getClass(); while (currentLevel != Activity.class) { if (currentLevel.getSimpleName().equals("SherlockActivity") || currentLevel.getSimpleName().equals("SherlockFragmentActivity")) { return Reflector.ActionBarType.ACTIONBAR_SHERLOCK; } if (currentLevel.getSimpleName().equals("ActionBarActivity")) { return Reflector.ActionBarType.APP_COMPAT; } currentLevel = currentLevel.getSuperclass(); } return Reflector.ActionBarType.STANDARD; }
Example 11
Source File: Utils.java From hipda with GNU General Public License v2.0 | 5 votes |
public static void restartActivity(Activity activity) { ColorHelper.clear(); activity.finish(); Intent intent = new Intent(activity.getApplicationContext(), activity.getClass()); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); activity.startActivity(intent); activity.overridePendingTransition(0, 0); System.exit(0); }
Example 12
Source File: Restarter.java From freeline with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Attempt to restart the app. Ideally this should also try to preserve as much state as * possible: * <ul> * <li>The current activity</li> * <li>If possible, state in the current activity, and</li> * <li>The activity stack</li> * </ul> * * This may require some framework support. Apparently it may already be possible * (Dianne says to put the app in the background, kill it then restart it; need to * figure out how to do this.) */ public static void restartApp(Context appContext, Collection<Activity> knownActivities, boolean toast) { if (!knownActivities.isEmpty()) { // Can't live patch resources; instead, try to restart the current activity Activity foreground = getForegroundActivity(appContext); if (foreground != null) { // http://stackoverflow.com/questions/6609414/howto-programatically-restart-android-app //noinspection UnnecessaryLocalVariable if (toast) { showToast(foreground, "Restarting app to apply incompatible changes"); } if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { Log.v(LOG_TAG, "RESTARTING APP"); } @SuppressWarnings("UnnecessaryLocalVariable") // fore code clarify Context context = foreground; Intent intent = new Intent(context, foreground.getClass()); int intentId = 0; PendingIntent pendingIntent = PendingIntent.getActivity(context, intentId, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, pendingIntent); if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { Log.v(LOG_TAG, "Scheduling activity " + foreground + " to start after exiting process"); } } else { showToast(knownActivities.iterator().next(), "Unable to restart app"); if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { Log.v(LOG_TAG, "Couldn't find any foreground activities to restart " + "for resource refresh"); } } System.exit(0); } }
Example 13
Source File: MTranstionUtil.java From MTransition with Apache License 2.0 | 5 votes |
private static void restoreAnimtaion(Activity activity) { Class clazz = activity.getClass(); if (sAnimationMap.containsKey(clazz)) { int animtaion = sAnimationMap.get(clazz); activity.getWindow().setWindowAnimations(animtaion); sAnimationMap.remove(clazz); } }
Example 14
Source File: MTranstionUtil.java From MTransition with Apache License 2.0 | 5 votes |
private static void saveAnimtaion(Activity activity) { Class clazz = activity.getClass(); if (!sAnimationMap.containsKey(clazz)) { int animtaion = activity.getWindow().getAttributes().windowAnimations; sAnimationMap.put(clazz, animtaion); } }
Example 15
Source File: ReflectorFactory.java From UltimateAndroid with Apache License 2.0 | 5 votes |
private static Reflector.ActionBarType searchForActivitySuperClass(Activity activity) { Class currentLevel = activity.getClass(); while (currentLevel != Activity.class) { if (currentLevel.getSimpleName().equals("SherlockActivity") || currentLevel.getSimpleName().equals("SherlockFragmentActivity")) { return Reflector.ActionBarType.ACTIONBAR_SHERLOCK; } if (currentLevel.getSimpleName().equals("ActionBarActivity")) { return Reflector.ActionBarType.APP_COMPAT; } currentLevel = currentLevel.getSuperclass(); } return Reflector.ActionBarType.STANDARD; }
Example 16
Source File: Restarter.java From android-advanced-decode with MIT License | 5 votes |
public static void restartApp(Context appContext, Collection<Activity> knownActivities, boolean toast) { if (!knownActivities.isEmpty()) { Activity foreground = getForegroundActivity(appContext); if (foreground != null) { if (toast) { showToast(foreground, "Restarting app to apply incompatible changes"); } if (Log.isLoggable("InstantRun", 2)) { Log.v("InstantRun", "RESTARTING APP"); } Context context = foreground; Intent intent = new Intent(context, foreground.getClass()); int intentId = 0; PendingIntent pendingIntent = PendingIntent.getActivity( context, intentId, intent, 268435456); AlarmManager mgr = (AlarmManager) context .getSystemService("alarm"); mgr.set(1, System.currentTimeMillis() + 100L, pendingIntent); if (Log.isLoggable("InstantRun", 2)) { Log.v("InstantRun", "Scheduling activity " + foreground + " to start after exiting process"); } } else { showToast((Activity) knownActivities.iterator().next(), "Unable to restart app"); if (Log.isLoggable("InstantRun", 2)) { Log.v("InstantRun", "Couldn't find any foreground activities to restart for resource refresh"); } } System.exit(0); } }
Example 17
Source File: MyActivityManager.java From Jide-Note with MIT License | 5 votes |
public void finishActivity(Class c){ for(Activity activity : activities){ if(activity.getClass() == c) { activity.finish(); activities.remove(activity); LogUtils.e("remove Activity"); } } }
Example 18
Source File: ActivityUtils.java From DevUtils with Apache License 2.0 | 4 votes |
/** * 结束多个类名 Activity * @param clazzs Class(Activity)[] * @return {@link ActivityUtils} */ public ActivityUtils finishActivity(final Class<?>... clazzs) { if (clazzs != null && clazzs.length != 0) { synchronized (mActivityStacks) { // 保存新的堆栈, 防止出现同步问题 Stack<Activity> stack = new Stack<>(); stack.addAll(mActivityStacks); // 清空全部, 便于后续操作处理 mActivityStacks.clear(); // 判断是否销毁 boolean isRemove; // 进行遍历移除 Iterator<Activity> iterator = stack.iterator(); while (iterator.hasNext()) { Activity activity = iterator.next(); // 判断是否想要关闭的 Activity if (activity != null) { // 默认不需要销毁 isRemove = false; // 循环判断 for (int i = 0, len = clazzs.length; i < len; i++) { // 判断是否相同 if (activity.getClass() == clazzs[i]) { isRemove = true; break; } } // 判断是否销毁 if (isRemove) { // 如果 Activity 没有 finish 则进行 finish if (!activity.isFinishing()) { activity.finish(); } // 删除对应的 Item iterator.remove(); } } else { // 删除对应的 Item iterator.remove(); } } // 把不符合条件的保存回去 mActivityStacks.addAll(stack); // 移除数据, 并且清空内存 stack.clear(); stack = null; } } return this; }
Example 19
Source File: ErrorDialogManager.java From KUtils with Apache License 2.0 | 4 votes |
/** Scope is limited to the activity's class. */ public static void attachTo(Activity activity, boolean finishAfterDialog, Bundle argumentsForErrorDialog) { Object executionScope = activity.getClass(); attachTo(activity, executionScope, finishAfterDialog, argumentsForErrorDialog); }
Example 20
Source File: DefaultAppLock.java From narrate-android with Apache License 2.0 | 3 votes |
@Override public void onActivityPaused(Activity arg0) { if( arg0.getClass() == PasscodeUnlockActivity.class ) return; if( ( this.appLockDisabledActivities != null ) && Arrays.asList(this.appLockDisabledActivities).contains( arg0.getClass().getName() ) ) return; lostFocusDate = new Date(); }