Thursday, October 29, 2015

Fragment transaction can't addToBackstack in Marshmallow

Add this piece of code to the underlying Activity


@Override
public void onBackPressed() {
    if (getFragmentManager().getBackStackEntryCount() > 0 ){
        getFragmentManager().popBackStack();
    } else {
        super.onBackPressed();
    }
}


Reference:

http://stackoverflow.com/a/28322881

Sunday, October 11, 2015

Using Relative project dependencies in Gradle for Android


First we create an Android project from Android Studio call MyLibrary.
Then remove the applicationId attribute from the build.gradle file and change the plugin from
apply plugin: 'com.android.application'
To
apply plugin: 'com.android.library'

That's all the changes we need to make with the library project.


Go back to our main project: MyApplication.

change the settings.gradle file to include our library project in the build.



Then we can configure our build.gradle file in MyApplication to add the dependency of MyLibrary project. In the dependencies section, add a line

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile project(':mylib')

}

Job done.

References:

http://stackoverflow.com/a/16999835