Java Code Examples for android.app.Activity#getParent()
The following examples show how to use
android.app.Activity#getParent() .
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: Restarter.java From android-advanced-decode with MIT License | 6 votes |
private static void restartActivity(Activity activity) { if (Log.isLoggable("InstantRun", 2)) { Log.v("InstantRun", "About to restart " + activity.getClass().getSimpleName()); } while (activity.getParent() != null) { if (Log.isLoggable("InstantRun", 2)) { Log.v("InstantRun", activity.getClass().getSimpleName() + " is not a top level activity; restarting " + activity.getParent().getClass().getSimpleName() + " instead"); } activity = activity.getParent(); } activity.recreate(); }
Example 2
Source File: NeptuneInstrument.java From Neptune with Apache License 2.0 | 6 votes |
@Override public void callActivityOnDestroy(Activity activity) { mHostInstr.callActivityOnDestroy(activity); if (activity.getParent() != null) { return; } final Intent intent = activity.getIntent(); String pkgName = IntentUtils.parsePkgNameFromActivity(activity); if (IntentUtils.isIntentForPlugin(intent) || intent == null) { // intent为null时,如果能够从Activity中解析出pkgName,也应该是插件的页面 if (!TextUtils.isEmpty(pkgName)) { PluginDebugLog.runtimeLog(TAG, "callActivityOnDestroy: " + pkgName); PluginLoadedApk loadedApk = PluginManager.getPluginLoadedApkByPkgName(pkgName); if (loadedApk != null) { loadedApk.getActivityStackSupervisor().popActivityFromStack(activity); } } } }
Example 3
Source File: Restarter.java From freeline with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static void restartActivity(Activity activity) { if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { Log.v(LOG_TAG, "About to restart " + activity.getClass().getSimpleName()); } // You can't restart activities that have parents: find the top-most activity while (activity.getParent() != null) { if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { Log.v(LOG_TAG, activity.getClass().getSimpleName() + " is not a top level activity; restarting " + activity.getParent().getClass().getSimpleName() + " instead"); } activity = activity.getParent(); } // Directly supported by the framework! activity.recreate(); }
Example 4
Source File: FeaturesUtils.java From Alibaba-Android-Certification with MIT License | 5 votes |
/** * 获取最顶层的父级Activity * @param activity 当前activity对象 * @return 没有父级Activity则返回当前activity */ public static Activity getTopActivity(Activity activity){ Activity topActivity=activity.getParent(); Activity result=topActivity; while(topActivity!=null){ topActivity=topActivity.getParent(); if(topActivity!=null){ result=topActivity; } } if(result==null){ result=activity; } return result; }
Example 5
Source File: GPTInstrumentation.java From GPT with Apache License 2.0 | 5 votes |
/** * 替换目标对象的window。 * * @param activity Activity */ private static void replaceWindow(Activity activity) { Activity parent = activity.getParent(); if (parent != null && parent instanceof ActivityProxy) { JavaCalls.setField(activity, "mWindow", parent.getWindow()); } replaceWindowCallback(activity); }
Example 6
Source File: Util.java From QSVideoPlayer with Apache License 2.0 | 5 votes |
public static Activity scanForActivity(Context context) { if (context instanceof Activity) { Activity a = (Activity) context; if (a.getParent() != null) return a.getParent(); else return a; } else if (context instanceof ContextWrapper) { return scanForActivity(((ContextWrapper) context).getBaseContext()); } throw new IllegalStateException("context得不到activity"); }
Example 7
Source File: WebSchemeIntent.java From YCWebView with Apache License 2.0 | 5 votes |
/** * 开启activity * @param intent intent * @param activity 上下文 * @throws WebViewException 异常,如果找不到,就会抛出异常,开发者也可以自己try-catch */ private static boolean startWithActivity(Intent intent, Activity activity) throws WebViewException { Activity target = activity.getParent(); if (target == null) { target = activity; } try { intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); return target.startActivityIfNeeded(intent, -1); } catch (ActivityNotFoundException e) { throw new WebViewException(3,MESSAGE_UNKNOWN); } }
Example 8
Source File: LocalizedActivity.java From ToGoZip with GNU General Public License v3.0 | 5 votes |
/** force all open activity to recreate */ public static void recreate(Activity child) { Activity context = child; while (context != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { context.recreate(); } else { // https://stackoverflow.com/questions/11495130/android-recreate-functions-in-api-7 context.startActivity(new Intent(context, context.getClass())); context.finish(); } context = context.getParent(); } }
Example 9
Source File: ActivityHelper.java From matomo-sdk-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static String getBreadcrumbs(final Activity activity) { Activity currentActivity = activity; ArrayList<String> breadcrumbs = new ArrayList<>(); while (currentActivity != null) { breadcrumbs.add(currentActivity.getTitle().toString()); currentActivity = currentActivity.getParent(); } return joinSlash(breadcrumbs); }
Example 10
Source File: Player.java From misound with Apache License 2.0 | 5 votes |
private ServiceToken bindToService(Activity context, ServiceConnection callback) { Activity realActivity = context.getParent(); if (realActivity == null) { realActivity = context; } ContextWrapper cw = new ContextWrapper(realActivity); cw.startService(new Intent(cw, PlayerService.class)); ServiceBinder sb = new ServiceBinder(callback); if (cw.bindService((new Intent()).setClass(cw, PlayerService.class), sb, 0)) { sConnectionMap.put(cw, sb); return new ServiceToken(cw); } Log.e(TAG, "Failed to bind to service"); return null; }
Example 11
Source File: GPTInstrumentation.java From GPT with Apache License 2.0 | 4 votes |
/** * onCallActivityOnCreate * * @param activity Activity */ private void onCallActivityOnCreate(Activity activity) { String packageName = activity.getPackageName(); boolean isPlugin = isPlugin(packageName); if (!isPlugin) { return; } if (ProxyEnvironment.pluginHotStartTimeMap.get(packageName) != null) { long stamp = ProxyEnvironment.pluginHotStartTimeMap.get(packageName); long millis = SystemClock.elapsedRealtime() - stamp; if (stamp > -1 && millis > 0) { ReportManger.getInstance().onPluginHotLoad(activity.getApplicationContext(), packageName, millis); ProxyEnvironment.pluginHotStartTimeMap.remove(packageName); } } replacePluginPackageName2Host(activity); replaceSystemServices(activity); replaceWindow(activity); replaceExternalDirs(activity); // 初始化 activity layoutinflator and localactivity manager Activity parent = activity.getParent(); if (parent != null && parent instanceof ActivityProxy) { ((ActivityProxy) parent).onBeforeCreate(activity); } if (Build.VERSION.SDK_INT < 23 /*Android m 6.0*/) { // bindservice trick begin // 如果在actiivty的 oncreate 中 binder service,token 中的 activity 对象为 null String className = "android.app.LocalActivityManager$LocalActivityRecord"; Class clazz = null; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { if (DEBUG) { e.printStackTrace(); } } IBinder token = JavaCalls.callMethod(activity.getBaseContext(), "getActivityToken"); if (clazz != null && token != null && token.getClass().equals(clazz)) { Activity a = (Activity) JavaCalls.getField(token, "activity"); if (a == null) { JavaCalls.setField(token, "activity", activity); } } // bindservice trick end } else { // 6.0 以上 Activity.mBase.mActvityToken 一直为 null,不使用也可以工作。 } }