1 Star 1 Fork 0

张小德 / MXStarter

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

MXStarter

解决的问题

Android开发中打开Activity并获取结果的原生方法:

    // 启动页面
    startActivityForResult(Intent(this,XXX::class.java), 0x22)

    // 获取结果
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 0x22){
            // 这里获取结果
        }
    }

当调用多个启动页面时,需要一个个判断requestCode并多次编写if xxx else xxx

使用MXStarter后,调用Activity方法如下:

MXStarter.start(this, ResultActivity::class.java) { resultCode: Int, data: Intent? ->
    // 这里获取结果
}

权限申请功能集成

在Activity和Fragment中可以直接获取权限申请回调,不需要再重载Activity的 onRequestPermissionsResult() 方法获取结果

MXPermission.requestPermission(
            activity,
            arrayOf(
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.WRITE_EXTERNAL_STORAGE
            )
        ) { allowed ->
            Toast.makeText(
                this@MainActivity,
                "获取权限:$allowed",
                Toast.LENGTH_SHORT
            ).show()
        }

Comments ( 0 )

Sign in for post a comment

About

Android简单的页面启动器,不用再使用onActivityResult来取得返回值 Kotlin + androidx 实现 spread retract
Cancel

Releases (5)

All

Contributors

All

Activities

load more
can not load any more
1
https://gitee.com/zhangmengxiong/MXStarter.git
git@gitee.com:zhangmengxiong/MXStarter.git
zhangmengxiong
MXStarter
MXStarter
master

Search