use of com.alibaba.android.arouter.facade.Postcard in project ARouter by alibaba.
the class SchemeFilterActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 直接通过ARouter处理外部Uri
Uri uri = getIntent().getData();
ARouter.getInstance().build(uri).navigation(this, new NavigationCallback() {
@Override
public void onFound(Postcard postcard) {
finish();
}
@Override
public void onLost(Postcard postcard) {
finish();
}
});
}
use of com.alibaba.android.arouter.facade.Postcard in project ARouter by alibaba.
the class MainActivity method onClick.
/**
* Called when a view has been clicked.
*
* @param v The view that was clicked.
*/
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.openLog:
ARouter.openLog();
break;
case R.id.openDebug:
ARouter.openDebug();
break;
case R.id.init:
// 调试模式不是必须开启,但是为了防止有用户开启了InstantRun,但是
// 忘了开调试模式,导致无法使用Demo,如果使用了InstantRun,必须在
// 初始化之前开启调试模式,但是上线前需要关闭,InstantRun仅用于开
// 发阶段,线上开启调试模式有安全风险,可以使用BuildConfig.DEBUG
// 来区分环境
ARouter.openDebug();
ARouter.init(getApplication());
break;
case R.id.normalNavigation:
ARouter.getInstance().build("/test/activity2").navigation();
break;
case R.id.normalNavigationWithParams:
ARouter.getInstance().build("/test/activity2").withString("key1", "value1").navigation();
break;
case R.id.interceptor:
ARouter.getInstance().build("/test/activity4").navigation();
break;
case R.id.navByUrl:
ARouter.getInstance().build("/test/webview").withString("url", "file:///android_asset/schame-test.html").navigation();
break;
case R.id.autoInject:
TestParcelable testParcelable = new TestParcelable("jack", 666);
TestObj testObj = new TestObj("Rose", 777);
ARouter.getInstance().build("/test/activity1").withString("name", "老王").withInt("age", 18).withBoolean("boy", true).withLong("high", 180).withString("url", "https://a.b.c").withParcelable("pac", testParcelable).withObject("obj", testObj).navigation();
break;
case R.id.navByName:
((HelloService) ARouter.getInstance().build("/service/hello").navigation()).sayHello("mike");
break;
case R.id.navByType:
ARouter.getInstance().navigation(HelloService.class).sayHello("mike");
break;
case R.id.navToMoudle1:
ARouter.getInstance().build("/module/1").navigation();
break;
case R.id.navToMoudle2:
// 这个页面主动指定了Group名
ARouter.getInstance().build("/module/2", "m2").navigation();
break;
case R.id.destroy:
ARouter.getInstance().destroy();
break;
case R.id.failNav:
ARouter.getInstance().build("/xxx/xxx").navigation(this, new NavigationCallback() {
@Override
public void onFound(Postcard postcard) {
}
@Override
public void onLost(Postcard postcard) {
Log.d("ARouter", "找不到了");
}
});
break;
case R.id.failNav2:
ARouter.getInstance().build("/xxx/xxx").navigation();
break;
case R.id.failNav3:
ARouter.getInstance().navigation(MainActivity.class);
break;
case R.id.normalNavigation2:
ARouter.getInstance().build("/test/activity2").navigation(this, 666);
break;
default:
break;
}
}
use of com.alibaba.android.arouter.facade.Postcard in project ARouter by alibaba.
the class InterceptorServiceImpl method _excute.
/**
* Excute interceptor
*
* @param index current interceptor index
* @param counter interceptor counter
* @param postcard routeMeta
*/
private static void _excute(final int index, final CancelableCountDownLatch counter, final Postcard postcard) {
if (index < Warehouse.interceptors.size()) {
IInterceptor iInterceptor = Warehouse.interceptors.get(index);
iInterceptor.process(postcard, new InterceptorCallback() {
@Override
public void onContinue(Postcard postcard) {
// Last interceptor excute over with no exception.
counter.countDown();
// When counter is down, it will be execute continue ,but index bigger than interceptors size, then U know.
_excute(index + 1, counter, postcard);
}
@Override
public void onInterrupt(Throwable exception) {
// Last interceptor excute over with fatal exception.
// save the exception message for backup.
postcard.setTag(null == exception ? new HandlerException("No message.") : exception.getMessage());
counter.cancel();
// Be attention, maybe the thread in callback has been changed,
// then the catch block(L207) will be invalid.
// The worst is the thread changed to main thread, then the app will be crash, if you throw this exception!
// if (!Looper.getMainLooper().equals(Looper.myLooper())) { // You shouldn't throw the exception if the thread is main thread.
// throw new HandlerException(exception.getMessage());
// }
}
});
}
}
use of com.alibaba.android.arouter.facade.Postcard in project ARouter by alibaba.
the class _ARouter method navigation.
protected <T> T navigation(Class<? extends T> service) {
try {
Postcard postcard = LogisticsCenter.buildProvider(service.getSimpleName());
LogisticsCenter.completion(postcard);
return (T) postcard.getProvider();
} catch (NoRouteFoundException ex) {
logger.warning(Consts.TAG, ex.getMessage());
return null;
}
}
Aggregations