GitHub - AnotherJack/AvoidOnResult: Avoid using onActivityResult () to improve c...
source link: https://github.com/AnotherJack/AvoidOnResult
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
原理讲解文章:避免使用onActivityResult,以提高代码可读性
配合AOP的实践文章:一个注解搞定登录注册、实名认证及购买vip等业务流程
优雅地封装和使用onActivityResult
-
无需重写onActivityResult,以回调的方式拿到startActivityForResult的结果,解决了以往跳转页面和处理结果分离的痛点。
-
同时无需重写onActivityResult也意味着只要你可以拿到一个Activity实例,就可以通过它startActivityForResult,甚至它是一个第三方库中的Activity也一样。
-
支持RxJava方式调用
Setup
-
in your root build.gradle
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
-
add to dependencies
dependencies { implementation 'com.github.AnotherJack:AvoidOnResult:1.0.0' }
Usage
-
callback方式
new AvoidOnResult(activity).startForResult(XXActivity.class, new AvoidOnResult.Callback() { @Override public void onActivityResult(int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK){ // get your data from intent }else { } } });
-
rxjava方式
new AvoidOnResult(activity).startForResult(MainActivity.class) //可自由变换 .filter(new Predicate<ActivityResultInfo>() { @Override public boolean test(ActivityResultInfo activityResultInfo) throws Exception { return activityResultInfo.getResultCode() == Activity.RESULT_OK; } }) .subscribe(new Observer<ActivityResultInfo>() { @Override public void onSubscribe(Disposable d) { } @Override public void onNext(ActivityResultInfo activityResultInfo) { } @Override public void onError(Throwable e) { } @Override public void onComplete() { } });
如果对你有所帮助,给个star吧
Recommend
-
70
(更新,已反射hook到onActivityResult)如何避免使用onActivityResult,以提高代码可读性 - 掘金 (更新,已反射hook到onActivityResult)如何避免使用onActivityResult,以提高代码可读性
-
64
当我们知道fragment仅仅可以收到自己请求的回调后,我们就可以用它来解耦activity中onActivityResult的逻辑了。一般情况下,如果一个activity中多个回调结果的话,onActivityResult()中会有各种case判断,并且这种
-
58
大家或许有遇到这个神坑,在Fragment中使用startActivityForResult能够成功,可是在Fragment中的onActivityResult却无法被调用。一不注意就让人一夜愁白了头。苦经探索(当然包括亲爱的百度和谷歌),终于总结出了一些规律。
-
4
Avoid coupling between Bounded Contexts using Weak SchemaHi, weʼre arkency 👋 The Rails Event Store comes with a
-
2
Most likely you’ve read many posts on how to use React hooks. But knowing how Not to use, sometimes, is equally important as knowing how to use. In this post, I will describe the React hooks usage mistakes, and how...
-
12
Using strace to avoid reading Ruby code This is the start of a new category! I just started at Stripe yesterday, so this is in the
-
4
【Android】onActivityResult()和onResume()的调用顺序问题 在Android生命周期中,如果使用到startActivityForResult(),则在新Activity被finish掉之后,onActivityResult()和onResume()到底...
-
3
Working on a project with many people whose demands and priorities keep changing can be dizzying. Even when you provide a scope of work, it seems like projects keep expanding and the work never ends. This is where you’ll often hear the term “...
-
32
onActivityResult and startActivityForResult deprecated41 viewsJul 20, 2021 This video contains...
-
2
Google Search will improve snippets to avoid misinformation Skip to main content
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK