Giter Site home page Giter Site logo

startactivityx's Introduction

Setup

dependencies {
    implementation "com.github.skgmn:startactivityx:1.2.0"
}

Features

startActivityForResult

lifecycleScope.launch {
    val activityResult = startActivityForResult(intent)
}

That's it. It provides some extension methods of ActivityResult for the convenience.

val ActivityResult.isOk: Boolean
val ActivityResult.isCanceled: Boolean
fun ActivityResult.getDataIfOk(): Intent?

So returned ActivityResult can be used like this in more kotlin way.

lifecycleScope.launch {
    startActivityForResult(intent).getDataIfOk()?.let { open(it) }
}

requestPermissions

lifecycleScope.launch {
    if (requestPermissions(Manifest.permission.CAMERA).granted) {
        // Permissions are granted here
        startCamera()
    }
}

Simple again. This single method also handles rationale dialog and do not ask again cases so there are no other things to acquire permissions.

There are some more features which are not documented yet. Please refer to source code and sample code to know about them.

PermissionStatus

Sometimes there needs to show or hide views according to whether permissions are granted or not. listenPermissionStatus() has been introduced to manage this case. It returns Flow<Boolean> which infinitely emits boolean values that indicate whether required permissions are granted.

lifecycleScope.launch {
    listenPermissonStatus(Manifest.permission.CAMERA).collect {
        binding.permissionsGranted = it.granted
    }
}
<Button
    android:text="Grant permissions"
    android:visibility="@{permissionsGranted ? View.GONE : View.VISIBLE}" />

Or getPermissionStatus() can be used to get PermissionStatus just once.

startActivityForInstance

This is some kind of bonus feature. It starts an Activity and returns its instance.

lifecycleScope.launch {
    val intent = ExplicitIntent(context, MyActivity::class.java)
    val activity = startActivityForInstance(intent)
}

startactivityx's People

Contributors

skgmn avatar

Stargazers

Greg Nightingale avatar zhangls avatar dreamboy1339 avatar  avatar eunho kim avatar

Watchers

 avatar

startactivityx's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.