-
Notifications
You must be signed in to change notification settings - Fork 516
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
在removeObserver的时候,如果livedata上没有observer,则删除这个livadata,以减少内存占用
- Loading branch information
liaohailiang
committed
Dec 27, 2018
1 parent
23a4c8a
commit 9ae7b8c
Showing
7 changed files
with
100 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
.../demo/src/androidTest/java/com/jeremyliao/liveeventbus/helper/LiveEventBusTestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.jeremyliao.liveeventbus.helper; | ||
|
||
import com.jeremyliao.liveeventbus.LiveEventBus; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by liaohailiang on 2018/12/27. | ||
*/ | ||
public class LiveEventBusTestHelper { | ||
|
||
private LiveEventBusTestHelper() { | ||
} | ||
|
||
public static int getLiveEventBusCount() { | ||
try { | ||
Field bus = LiveEventBus.class.getDeclaredField("bus"); | ||
bus.setAccessible(true); | ||
Map map = (Map) bus.get(LiveEventBus.get()); | ||
return map.size(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return -1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ntbus/src/androidTest/java/com/jeremyliao/liveeventbus/helper/LiveEventBusTestHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.jeremyliao.liveeventbus.helper; | ||
|
||
import com.jeremyliao.liveeventbus.LiveEventBus; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by liaohailiang on 2018/12/27. | ||
*/ | ||
public class LiveEventBusTestHelper { | ||
|
||
private LiveEventBusTestHelper() { | ||
} | ||
|
||
public static int getLiveEventBusCount() { | ||
try { | ||
Field bus = LiveEventBus.class.getDeclaredField("bus"); | ||
bus.setAccessible(true); | ||
Map map = (Map) bus.get(LiveEventBus.get()); | ||
return map.size(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return -1; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters