Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest Android version, add new onAttach() lifecycle callba… #26

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions tools/LifecycleLog/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
compileSdkVersion 24
buildToolsVersion "24.0.3"

defaultConfig {
applicationId "com.example.lifecyclelog"
minSdkVersion 8
targetSdkVersion 19
minSdkVersion 9
targetSdkVersion 24
}

buildTypes {
release {
runProguard false
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile 'com.android.support:support-v4:20.+'
compile 'com.android.support:support-v4:24.2.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
Expand All @@ -14,7 +15,7 @@
import static com.example.lifecyclelog.Util.LifecycleState.RETURN_FROM_SUPER;
import static com.example.lifecyclelog.Util.recLifeCycle;

@TargetApi(Build.VERSION_CODES.KITKAT)
@TargetApi(Build.VERSION_CODES.M)
public class TestFragment extends Fragment {

@Override
Expand Down Expand Up @@ -50,11 +51,34 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

}

@TargetApi(Build.VERSION_CODES.M)
@Override
public void onAttach(Context context) {
recLifeCycle(getClass(), CALL_TO_SUPER);
super.onAttach(context);
recLifeCycle(getClass(), RETURN_FROM_SUPER);
commonOnAttach(getActivity());
}

/*
* Deprecated on API 23
* Use onAttachToContext instead
*/
@SuppressWarnings("deprecation")
@Override
public void onAttach(Activity activity) {
recLifeCycle(getClass(), CALL_TO_SUPER);
super.onAttach(activity);
recLifeCycle(getClass(), RETURN_FROM_SUPER);

// Prevent double call - Android M calls both onAttach() lifecycle functions for backward compatibility
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
commonOnAttach(activity);
}
}

private void commonOnAttach(Activity activity) {
// Do some stuff for attach.
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
tools:context=".MainActivity" >

<fragment android:id="@+id/test_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.lifecyclelog.TestCompatFragment" />
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.lifecyclelog.TestCompatFragment"
tools:layout="@layout/fragment_test"/>

</RelativeLayout>
2 changes: 1 addition & 1 deletion tools/LifecycleLog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.12.2'
classpath 'com.android.tools.build:gradle:2.2.2'
}
}

Expand Down