1
0
mirror of https://github.com/TwidereProject/Twidere-Android synced 2025-02-11 01:00:42 +01:00

fixed crashes on pre-marshmallow devices

This commit is contained in:
Mariotaku Lee 2015-10-10 10:08:31 +08:00
parent 05e76a1fd4
commit 7f48a7342c
7 changed files with 24 additions and 17 deletions

View File

@ -14,7 +14,7 @@ android {
applicationId "org.mariotaku.twidere" applicationId "org.mariotaku.twidere"
minSdkVersion 14 minSdkVersion 14
targetSdkVersion 23 targetSdkVersion 23
versionCode 126 versionCode 128
versionName "0.3.0" versionName "0.3.0"
multiDexEnabled true multiDexEnabled true
} }

View File

@ -424,7 +424,6 @@ public class HomeActivity extends BaseAppCompatActivity implements OnClickListen
if (Utils.isStreamingEnabled()) { if (Utils.isStreamingEnabled()) {
startService(new Intent(this, StreamingService.class)); startService(new Intent(this, StreamingService.class));
} }
} }
@Override @Override

View File

@ -64,7 +64,8 @@ import static org.mariotaku.twidere.util.Utils.initAccountColor;
import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded; import static org.mariotaku.twidere.util.Utils.startRefreshServiceIfNeeded;
@ReportsCrashes(formUri = "https://twidere-bugreport.herokuapp.com/reports", @ReportsCrashes(formUri = "https://twidere-bugreport.herokuapp.com/reports",
buildConfigClass = BuildConfig.class) buildConfigClass = BuildConfig.class, sendReportsInDevMode = false,
sendReportsAtShutdown = false)
public class TwidereApplication extends MultiDexApplication implements Constants, public class TwidereApplication extends MultiDexApplication implements Constants,
OnSharedPreferenceChangeListener { OnSharedPreferenceChangeListener {
@ -170,9 +171,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants
private void initBugReport() { private void initBugReport() {
final SharedPreferences preferences = getSharedPreferences(); final SharedPreferences preferences = getSharedPreferences();
if (!preferences.getBoolean(KEY_BUG_REPORTS, true)) return; if (!preferences.getBoolean(KEY_BUG_REPORTS, true)) return;
if (!BuildConfig.DEBUG) { AbsLogger.setImplementation(new TwidereLogger());
AbsLogger.setImplementation(new TwidereLogger());
}
AbsLogger.init(this); AbsLogger.init(this);
} }

View File

@ -23,7 +23,6 @@ import android.app.Activity;
import android.app.Fragment; import android.app.Fragment;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -43,10 +42,12 @@ public class BaseFragment extends Fragment implements Constants {
@Inject @Inject
protected SharedPreferencesWrapper mPreferences; protected SharedPreferencesWrapper mPreferences;
@SuppressWarnings("deprecated")
@Override @Override
public void onAttach(Context context) { public void onAttach(Activity activity) {
super.onAttach(context); super.onAttach(activity);
DaggerGeneralComponent.builder().applicationModule(ApplicationModule.get(context)).build().inject(this); DaggerGeneralComponent.builder().applicationModule(ApplicationModule.get(activity)).build().inject(this);
} }
public TwidereApplication getApplication() { public TwidereApplication getApplication() {

View File

@ -19,7 +19,7 @@
package org.mariotaku.twidere.fragment; package org.mariotaku.twidere.fragment;
import android.content.Context; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
@ -38,10 +38,11 @@ public class BasePreferenceFragment extends PreferenceFragment implements Consta
@Inject @Inject
protected UserColorNameManager mUserColorNameManager; protected UserColorNameManager mUserColorNameManager;
@SuppressWarnings("deprecated")
@Override @Override
public void onAttach(Context context) { public void onAttach(Activity activity) {
super.onAttach(context); super.onAttach(activity);
DaggerGeneralComponent.builder().applicationModule(ApplicationModule.get(context)).build().inject(this); DaggerGeneralComponent.builder().applicationModule(ApplicationModule.get(activity)).build().inject(this);
} }
@Override @Override

View File

@ -25,6 +25,7 @@ import android.support.annotation.Nullable;
import android.util.Log; import android.util.Log;
import org.acra.ACRA; import org.acra.ACRA;
import org.acra.ACRAConfiguration;
import org.mariotaku.twidere.BuildConfig; import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.Constants; import org.mariotaku.twidere.Constants;
@ -70,15 +71,16 @@ public class TwidereLogger extends AbsLogger implements Constants {
protected void initImpl(final Application application) { protected void initImpl(final Application application) {
// ACRA sets it self as DefaultUncaughtExceptionHandler, we hijack it to suppress some errors // ACRA sets it self as DefaultUncaughtExceptionHandler, we hijack it to suppress some errors
ACRA.init(application); ACRA.init(application);
final ACRAConfiguration conf = ACRA.getNewDefaultConfig(application);
ACRA.setConfig(conf);
// handler should be ACRA's ErrorReporter now // handler should be ACRA's ErrorReporter now
final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler(); final Thread.UncaughtExceptionHandler handler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override @Override
public void uncaughtException(Thread thread, Throwable ex) { public void uncaughtException(Thread thread, Throwable ex) {
// We can't fix OOM, so just don't report it and try to save VM // We can't fix OOM, so just don't report it and try to save VM
if (!Utils.isOutOfMemory(ex)) { if (Utils.isOutOfMemory(ex)) return;
handler.uncaughtException(thread, ex); handler.uncaughtException(thread, ex);
}
} }
}); });
} }

View File

@ -86,6 +86,11 @@ public class ApplicationModule {
} }
sharedPreferences = SharedPreferencesWrapper.getInstance(application, Constants.SHARED_PREFERENCES_NAME, sharedPreferences = SharedPreferencesWrapper.getInstance(application, Constants.SHARED_PREFERENCES_NAME,
Context.MODE_PRIVATE, SharedPreferenceConstants.class); Context.MODE_PRIVATE, SharedPreferenceConstants.class);
if (sharedPreferences == null) {
throw new RuntimeException("SharedPreferences must not be null");
}
activityTracker = new ActivityTracker(); activityTracker = new ActivityTracker();
bus = new Bus(ThreadEnforcer.MAIN); bus = new Bus(ThreadEnforcer.MAIN);
asyncTaskManager = AsyncTaskManager.getInstance(); asyncTaskManager = AsyncTaskManager.getInstance();