Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear persistent component when activity throw exception #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
Expand Down Expand Up @@ -35,7 +36,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Create the ActivityComponent and reuses cached ConfigPersistentComponent if this is
// being called after a configuration change.
mActivityId = savedInstanceState != null ?
savedInstanceState.getLong(KEY_ACTIVITY_ID) : NEXT_ID.getAndIncrement();
savedInstanceState.getLong(KEY_ACTIVITY_ID) : NEXT_ID.getAndIncrement();
ConfigPersistentComponent configPersistentComponent;
if (!sComponentsMap.containsKey(mActivityId)) {
Timber.i("Creating new ConfigPersistentComponent id=%d", mActivityId);
Expand All @@ -48,6 +49,15 @@ protected void onCreate(Bundle savedInstanceState) {
configPersistentComponent = sComponentsMap.get(mActivityId);
}
mActivityComponent = configPersistentComponent.activityComponent(new ActivityModule(this));

final UncaughtExceptionHandler exceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
sComponentsMap.remove(mActivityId);
exceptionHandler.uncaughtException(thread, throwable);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ protected void onCreate(Bundle savedInstanceState) {
if (getIntent().getBooleanExtra(EXTRA_TRIGGER_SYNC_FLAG, true)) {
startService(SyncService.getStartIntent(this));
}

}

@Override
Expand Down