一个轻巧的,用于解耦startActivityForResult方法的库。
项目级别的build.gradle
文件加入:
allprojects {
repositories {
...
maven { url 'https://dl.bintray.com/lesincs/maven' }
}
}
模组级别build.gradle
文件添加 依赖 :
dependencies {
...
implementation com.github.lesincs:StartActivityForResultHelper:1.0.0
}
start:
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
StartActivityForResultHelper.startActivityForResult(FirstActivity.this, intent, new ActivityResultCallback() {
@Override
public void onResult(int resultCode, Intent intent) {
Log.d(TAG,"resultCode = " + resultCode );
Log.d(TAG,"data = " + intent.getStringExtra(Constants.EXTRA_KEY));
}
});
finish:
Intent intent = new Intent();
intent.putExtra(Constants.EXTRA_KEY,"DATA");
setResult(Constants.RESULT_CODE,intent);
finish();
- 无需重写
OnActivityResult方法
,减少代码耦合 - 不需要关注
REQUEST_CODE
- 支持
Activity
和Fragment
- 体积小巧,没有引用多余的第三方库
Copyright 2019 lesincs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.