/** * Get the field in this or any superclass. * * @param clazz * @param name * @return The field or null if not found */ public static Field getDeclaredField(Class<?> clazz, String name) { if (clazz == null || name == null) return null; try { Field field = clazz.getDeclaredField(name); return field; } catch (NoSuchFieldException e) { } return getDeclaredField(clazz.getSuperclass(), name); }
public static int getStatus(TimerTask task) { if (task == null) return -1; try { Class<? extends TimerTask> clazz = task.getClass(); Field field = MSystem.getDeclaredField(clazz,"state"); if (field != null) { if (!field.isAccessible()) field.setAccessible(true); return field.getInt(task); } } catch (Throwable t) { MLogUtil.log().d(task,t); } return -1; }