Router { public Intent getIntent(String url, Bundle bundle, Context context) { Request request = urlMatcher.match(url); if (request.getCompiledRoute() == null) { if (mismatchedHandler != null) { mismatchedHandler.run(request, this); } return null; } CompiledRoute compiledRoute = request.getCompiledRoute(); String activityClassName = compiledRoute.getActivityClass(); Class activityClass = null; try { activityClass = Class.forName(activityClassName); } catch (ClassNotFoundException e) { e.printStackTrace(); } if (activityClass == null) { return null; } Intent intent = new Intent(context, activityClass); if (bundle == null) { bundle = new Bundle(); } if (request.getQueryVariables() != null) { for (String queryKey : request.getQueryVariables().keySet()) { bundle.putString(queryKey, request.getQueryVariables().get(queryKey)); } } if (request.getPathVariables() != null) { for (String queryKey : request.getPathVariables().keySet()) { bundle.putString(queryKey, request.getPathVariables().get(queryKey)); } } if (!(context instanceof Activity)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } request.setRefererClass(context.getClass().getName()); bundle.putParcelable(BUNDLE_KEY_REQUEST, request); intent.putExtras(bundle); return intent; } Router(UrlMatcher urlMatcher, RouteCompiler routeCompiler, Context context);  Router(Context context); Router setContext(Context context); Context getContext(); Router mismatched(MismatchedHandler mismatchedHandler); Router add(Route route); Router add(String path, Class<? extends Activity> activityClass); Router asShared(); static Router getShared(); void open(String url); void open(String url, Context context); void open(String url, Bundle bundle); void open(String url, Context context, Bundle bundle); void openForResult(String url, Activity sourceActivity, int requestCode); void openForResult(String url, Activity sourceActivity, int requestCode, Bundle bundle); void openExternal(String url); Intent getIntent(String url, Bundle bundle, Context context); Request getRequest(Bundle bundle); void proxy(Bundle bundle, RouterProxy routerProxy); void proxy(Request request, RouterProxy routerProxy); static final String BUNDLE_KEY_REQUEST; }
@Test public void testGetIntent() { router.add(new Route("github.com/{vendor}", VendorActivity.class)); Bundle bundle = new Bundle(); Intent intent = router.getIntent("https: ; assertEquals( Intent.FLAG_ACTIVITY_NEW_TASK, intent.getFlags() ); assertEquals("mr5", bundle.getString("vendor")); assertEquals("haha", bundle.getString("q")); assertEquals(bundle, intent.getExtras()); Bundle bundle4Variables = new Bundle(); router.getIntent("https: assertEquals("mr5", bundle4Variables.get("vendor")); assertEquals( 0, router.getIntent( "https: new Bundle(), new Activity()).getFlags() ); }