-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
195 additions
and
265 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
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
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
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/wrbug/developerhelper/util/AppStatusRegister.kt
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,56 @@ | ||
package com.wrbug.developerhelper.util | ||
|
||
import android.app.Activity | ||
import android.app.Application | ||
import android.os.Bundle | ||
|
||
object AppStatusRegister { | ||
private var count = 0 | ||
private val backgroundMap = hashMapOf<String, () -> Unit>() | ||
fun init(application: Application) { | ||
application.registerActivityLifecycleCallbacks(object : | ||
Application.ActivityLifecycleCallbacks { | ||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { | ||
|
||
} | ||
|
||
override fun onActivityStarted(activity: Activity) { | ||
count++ | ||
} | ||
|
||
override fun onActivityResumed(activity: Activity) { | ||
} | ||
|
||
override fun onActivityPaused(activity: Activity) { | ||
} | ||
|
||
override fun onActivityStopped(activity: Activity) { | ||
count-- | ||
backgroundCheck() | ||
} | ||
|
||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { | ||
} | ||
|
||
override fun onActivityDestroyed(activity: Activity) { | ||
} | ||
|
||
}) | ||
} | ||
|
||
|
||
fun registerBackgroundListener(key: String, listener: () -> Unit) { | ||
backgroundMap[key] = listener | ||
} | ||
|
||
fun removeBackgroundListener(key: String) { | ||
backgroundMap.remove(key) | ||
} | ||
|
||
private fun backgroundCheck() { | ||
if (count == 0) { | ||
backgroundMap.values.forEach { it() } | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.