Giter VIP home page Giter VIP logo

today-i-learned's Issues

runtime-perm.md initApp() before Permissions Granted

Hi,

first of all: Thank you very much for your lessions and the effort you put into this. Much appreceated!

I found an issue in you runtime permissions writeup. In the onRequestPermissionsResult callback you are just checking if permissions are denied and if not initApp() is called. This bypasses the logic that the initApp() should only be called if permissions are granted. I have solved this by changing it to the following:

            int deniedCount = 0;
            int grantedCount = 0;

            // Gather permission grant results
            for (int i=0; i<grantResults.length; i++)
            {
                // Add only permissions which are denied
                if (grantResults[i] == PackageManager.PERMISSION_DENIED)
                {

                    permissionResults.put(permissions[i], grantResults[i]);
                    deniedCount++;
                }
                if (grantResults[i] == PackageManager.PERMISSION_GRANTED)
                {

                    permissionResults.put(permissions[i], grantResults[i]);
                    grantedCount++;
                }
            }

            // Check if all permissions are granted
            if (deniedCount == 0 && grantedCount != 0)

ReuireContext and RequireActivity description isn't accurate

Topic
https://github.com/wajahatkarim3/Today-I-Learned/blob/master/android/req-act.md

Section
Now, this method will make sure that Fragment is attached and returns a valid non-null Activity which we can use without any trouble.

This part isn't true in fact I'm not really sure of the purpose of these methods since they throw an IllegalStateException if your activity is detached rather than the nullable context unwrapping method.

Ref:

    public final Context requireContext() {
        Context context = getContext();
        if (context == null) {
            throw new IllegalStateException("Fragment " + this + " not attached to a context.");
        }
        return context;
    }

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.