-
-
Notifications
You must be signed in to change notification settings - Fork 435
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
35 changed files
with
1,514 additions
and
185 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
80 changes: 80 additions & 0 deletions
80
sentry-android-core/src/main/java/io/sentry/android/core/CurrentActivityIntegration.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,80 @@ | ||
package io.sentry.android.core; | ||
|
||
import android.app.Activity; | ||
import android.app.Application; | ||
import android.os.Bundle; | ||
import androidx.annotation.NonNull; | ||
import io.sentry.IHub; | ||
import io.sentry.Integration; | ||
import io.sentry.SentryOptions; | ||
import io.sentry.util.Objects; | ||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@ApiStatus.Internal | ||
public final class CurrentActivityIntegration | ||
implements Integration, Closeable, Application.ActivityLifecycleCallbacks { | ||
|
||
private final @NotNull Application application; | ||
|
||
public CurrentActivityIntegration(final @NotNull Application application) { | ||
this.application = Objects.requireNonNull(application, "Application is required"); | ||
} | ||
|
||
@Override | ||
public void register(@NotNull IHub hub, @NotNull SentryOptions options) { | ||
application.registerActivityLifecycleCallbacks(this); | ||
} | ||
|
||
@Override | ||
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { | ||
setCurrentActivity(activity); | ||
} | ||
|
||
@Override | ||
public void onActivityStarted(@NonNull Activity activity) { | ||
setCurrentActivity(activity); | ||
} | ||
|
||
@Override | ||
public void onActivityResumed(@NonNull Activity activity) { | ||
setCurrentActivity(activity); | ||
} | ||
|
||
@Override | ||
public void onActivityPaused(@NonNull Activity activity) { | ||
cleanCurrentActivity(activity); | ||
} | ||
|
||
@Override | ||
public void onActivityStopped(@NonNull Activity activity) { | ||
cleanCurrentActivity(activity); | ||
} | ||
|
||
@Override | ||
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) {} | ||
|
||
@Override | ||
public void onActivityDestroyed(@NonNull Activity activity) { | ||
cleanCurrentActivity(activity); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
application.unregisterActivityLifecycleCallbacks(this); | ||
CurrentActivityHolder.getInstance().clearActivity(); | ||
} | ||
|
||
private void cleanCurrentActivity(final @NotNull Activity activity) { | ||
if (CurrentActivityHolder.getInstance().getActivity() == activity) { | ||
CurrentActivityHolder.getInstance().clearActivity(); | ||
} | ||
} | ||
|
||
private void setCurrentActivity(final @NotNull Activity activity) { | ||
CurrentActivityHolder.getInstance().setActivity(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
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.