-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: crashes when app in foreground and try to show downing progress …
…notification (#26)
- Loading branch information
1 parent
5a7ec0a
commit b60fb05
Showing
3 changed files
with
150 additions
and
9 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
71 changes: 71 additions & 0 deletions
71
demos/main/src/main/java/androidx/media3/demo/main/DemoApplication.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,71 @@ | ||
package androidx.media3.demo.main; | ||
|
||
import android.app.Activity; | ||
import android.os.Bundle; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.OptIn; | ||
import androidx.media3.common.util.UnstableApi; | ||
import androidx.multidex.MultiDexApplication; | ||
|
||
public final class DemoApplication extends MultiDexApplication { | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { | ||
private int started = 0; | ||
private int resumed = 0; | ||
private int stopped = 0; | ||
|
||
private boolean isAppBackFromBackground() { | ||
return started == stopped + 1 && stopped > 0 && resumed == started; | ||
} | ||
|
||
private boolean isAppEnterBackground() { | ||
return stopped == started; | ||
} | ||
|
||
@Override | ||
public void onActivityStarted(@NonNull Activity activity) { | ||
++started; | ||
} | ||
|
||
@OptIn(markerClass = UnstableApi.class) | ||
@Override | ||
public void onActivityResumed(@NonNull Activity activity) { | ||
++resumed; | ||
if (isAppBackFromBackground()) { | ||
DemoDownloadService.sendRefreshForeground(activity, DemoDownloadService.class); | ||
} | ||
} | ||
|
||
@Override | ||
public void onActivityStopped(@NonNull Activity activity) { | ||
++stopped; | ||
resumed = started; | ||
if (isAppEnterBackground()) { | ||
// app enter background | ||
} | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@NonNull Activity activity, | ||
@Nullable Bundle savedInstanceState) { | ||
} | ||
|
||
@Override | ||
public void onActivityPaused(@NonNull Activity activity) { | ||
} | ||
|
||
@Override | ||
public void onActivitySaveInstanceState(@NonNull Activity activity, | ||
@NonNull Bundle outState) { | ||
} | ||
|
||
@Override | ||
public void onActivityDestroyed(@NonNull Activity activity) { | ||
} | ||
}); | ||
} | ||
} |
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