-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from SpaceMadness/fix/android-resume-black-sc…
…reen Fix Android black screen while resuming
- Loading branch information
Showing
7 changed files
with
229 additions
and
61 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
98 changes: 98 additions & 0 deletions
98
...Console/src/main/java/spacemadness/com/lunarconsole/console/ActivityLifecycleHandler.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,98 @@ | ||
package spacemadness.com.lunarconsole.console; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
|
||
import java.lang.ref.WeakReference; | ||
|
||
import spacemadness.com.lunarconsole.core.Destroyable; | ||
import spacemadness.com.lunarconsole.core.NotificationCenter; | ||
|
||
import static spacemadness.com.lunarconsole.console.Notifications.NOTIFICATION_ACTIVITY_STARTED; | ||
import static spacemadness.com.lunarconsole.console.Notifications.NOTIFICATION_ACTIVITY_STOPPED; | ||
import static spacemadness.com.lunarconsole.console.Notifications.NOTIFICATION_KEY_ACTIVITY; | ||
|
||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | ||
class ActivityLifecycleHandler implements Application.ActivityLifecycleCallbacks, Destroyable | ||
{ | ||
private final WeakReference<Application> applicationRef; | ||
|
||
public ActivityLifecycleHandler(Application application) | ||
{ | ||
if (application == null) | ||
{ | ||
throw new IllegalArgumentException("Application is null"); | ||
} | ||
applicationRef = new WeakReference<>(application); | ||
application.registerActivityLifecycleCallbacks(this); | ||
} | ||
|
||
//region Activity Lifecycle Callbacks | ||
|
||
@Override | ||
public void onActivityCreated(Activity activity, Bundle savedInstanceState) | ||
{ | ||
} | ||
|
||
@Override | ||
public void onActivityStarted(Activity activity) | ||
{ | ||
NotificationCenter.defaultCenter() | ||
.postNotification(NOTIFICATION_ACTIVITY_STARTED, NOTIFICATION_KEY_ACTIVITY, activity); | ||
} | ||
|
||
@Override | ||
public void onActivityResumed(Activity activity) | ||
{ | ||
} | ||
|
||
@Override | ||
public void onActivityPaused(Activity activity) | ||
{ | ||
} | ||
|
||
@Override | ||
public void onActivityStopped(Activity activity) | ||
{ | ||
NotificationCenter.defaultCenter() | ||
.postNotification(NOTIFICATION_ACTIVITY_STOPPED, NOTIFICATION_KEY_ACTIVITY, activity); | ||
} | ||
|
||
@Override | ||
public void onActivitySaveInstanceState(Activity activity, Bundle outState) | ||
{ | ||
} | ||
|
||
@Override | ||
public void onActivityDestroyed(Activity activity) | ||
{ | ||
} | ||
|
||
//endregion | ||
|
||
//region Destroyable | ||
|
||
@Override | ||
public void destroy() | ||
{ | ||
Application application = getApplication(); | ||
if (application != null) | ||
{ | ||
application.unregisterActivityLifecycleCallbacks(this); | ||
} | ||
} | ||
|
||
//endregion | ||
|
||
//region Helpers | ||
|
||
private Application getApplication() | ||
{ | ||
return applicationRef.get(); | ||
} | ||
|
||
//endregion | ||
} |
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
Oops, something went wrong.