warning: [deprecation] getColor(int) in Resources has been deprecated

Reference:

https://developer.android.com/reference/android/content/res/Resources#getColor(int)https://developer.android.com/reference/android/content/res/Resources#getColor(int)

This method is deprecated from API level 23, so you can safely manage this situation with:

int MyColor=0;
if (Build.VERSION.SDK_INT >= 23) // the new version of the API
     myColor = getResources()
        .getColor(
            R.color.primaryColor, 
            getActivity.getTheme()
        )
     );
else  // the old version of the API
    myColor = getResources()
        .getColor(R.color.primaryColor));

warning: [deprecation] getInstallerPackageName(String) in PackageManager has been deprecated

Reference: https://developer.android.com/reference/android/content/pm/PackageManager#getInstallerPackageName(java.lang.String)

This Method is deprecated from API level 30, so you can safely manage this situation with:

if (Build.VERSION.SDK_INT >= 30) {

    InstallSourceInfo isi = getContext()
        .getPackageManager()
        .getInstallSourceInfo(getContext()
        .getPackageName());

    // now, with an InstallSourceInfo object, you have access to three useful methods

    String initiating = isi.getInitiatingPackageName();
    String installing = isi.getInstallingPackageName();
    String originating = isi.getOriginatingPackageName();

} else { // continue to use the old version API

    String installerPackageName = getContext()
        .getPackageManager()
        .getInstallerPackageName(
            getContext().getPackageName()
        );
}

getInitiatingPackageName returns the name of the package that requested the installation, or null if not available. This is normally the same as the old getInstallerPackageName.

Multitasking on android

In the last years working with multitasking on Android was a bit tricky but after a lot of study I have worked out this. The playground was full of scattered objects with a high learning curve and with one only exit: abandon all frameworks and pass on base objects.

At the end of the study, all limits to one and only simple object on which to build all you personal framework: the Thread object.

Continue reading “Multitasking on android”

Request Permission with new API

Before June 2020 the request permission at runtime happened through requestPermission() and requestPermissionResult(). After that date the things are become a bit tricky. Requesting a permission has been inglobated in a more general way of “Getting a result from an activity” by “Registering a callback for an activity result”. Here are the documents: Getting a result from an activity.

Continue reading “Request Permission with new API”

Android Studio: Cannot resolve ‘method’ and other strange odd behaviours

Scenario: You are working on the same Android Studio project on multiple computers, carrying the essential files on a pen drive, or on the cloud or whatever you want. Open the project and mysteriously some methods (more than one surely) aren’t recognized anymore, or some classes, or just variables. But the project compiles and runs fine!!! Syncing/building don’t resolve this thing.

Continue reading “Android Studio: Cannot resolve ‘method’ and other strange odd behaviours”