Skip to content
Merged
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
31 changes: 1 addition & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,37 +232,8 @@ You could use `DebugDrawer` or `DebugView` depending on your needs
}
```

### 2. Lifecycle
If you use `NetworkModule`, `LocationModule`, `FpsModule` or your own which is hooked with BroadcastReceivers you must call `onStart`/`onStop`, `onResume`/`onPause` in your activity
### 2. `TimberModule`

```java

@Override
protected void onStart() {
super.onStart();
debugDrawer.onStart();
}

@Override
protected void onResume() {
super.onResume();
debugDrawer.onResume();
}

@Override
protected void onPause() {
super.onPause();
debugDrawer.onPause();
}

@Override
protected void onStop() {
super.onStop();
debugDrawer.onStop();
}
```

### 3. `TimberModule`
Don't forget to plant needed log trees in Application class. Tree that is used by `TimberModule` stored in `LumberYard` class.

Application class example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.widget.ScrollView;

import io.palaima.debugdrawer.base.DebugModule;
import io.palaima.debugdrawer.util.DebugDrawerLifecycleCallbacks;
import io.palaima.debugdrawer.util.UIUtils;
import io.palaima.debugdrawer.view.DebugView;
import io.palaima.debugdrawer.view.ScrimInsetsFrameLayout;
Expand Down Expand Up @@ -399,6 +400,9 @@ public void onDrawerStateChanged(int newState) {
//create the result object
DebugDrawer result = new DebugDrawer(this);

//register a lifecycle callback for start, stop, pause and resume events
activity.getApplication().registerActivityLifecycleCallbacks(new DebugDrawerLifecycleCallbacks(activity, result));

//forget the reference to the activity
activity = null;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.palaima.debugdrawer.util;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import io.palaima.debugdrawer.DebugDrawer;

public class DebugDrawerLifecycleCallbacks implements Application.ActivityLifecycleCallbacks {
private Activity mActivity;
private DebugDrawer mDebugDrawer;

public DebugDrawerLifecycleCallbacks(Activity activity, DebugDrawer debugDrawer) {
mActivity = activity;
mDebugDrawer = debugDrawer;
}

@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

}

@Override
public void onActivityStarted(Activity activity) {
if (mActivity == activity) {
mDebugDrawer.onStart();
}
}

@Override
public void onActivityResumed(Activity activity) {
if (mActivity == activity) {
mDebugDrawer.onResume();
}
}

@Override
public void onActivityPaused(Activity activity) {
if (mActivity == activity) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may use .equals() instead for checking equality in objects?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the lifecycle callbacks and the debug drawer are installed for that particular instance of an Activity I think you would have to check if they are actually the same instance. So object equality is needed here

Copy link
Copy Markdown
Author

@remcomokveld remcomokveld Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also android.app.Activity itself does not override equals() itself the implementation from the Object class will be used which is return (this == obj);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true story just also checked that equals is not be overrided by activity

mDebugDrawer.onPause();
}
}

@Override
public void onActivityStopped(Activity activity) {
if (mActivity == activity) {
mDebugDrawer.onStop();
}
}

@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

}

@Override
public void onActivityDestroyed(Activity activity) {
mActivity.getApplication().unregisterActivityLifecycleCallbacks(this);
mActivity = null;
mDebugDrawer = null;
}
}