Skip to content

一个轻巧的,用于解耦startActivityForResult方法的库。

Notifications You must be signed in to change notification settings

Lesincs/StartActivityForResultHelper

Repository files navigation

StartActivityForResultHelper

一个轻巧的,用于解耦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
  • 支持ActivityFragment
  • 体积小巧,没有引用多余的第三方库

License

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.

About

一个轻巧的,用于解耦startActivityForResult方法的库。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages