mirror of
https://github.com/etesync/android
synced 2024-12-23 15:18:14 +00:00
Fix crash bug caused by leaking OnAccountsUpdateListener
This commit is contained in:
parent
940d622402
commit
3ca063416e
@ -72,5 +72,5 @@ dependencies {
|
||||
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.1.2'
|
||||
compile 'dnsjava:dnsjava:2.1.7'
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
compile 'org.slf4j:slf4j-android:1.7.13'
|
||||
compile 'org.slf4j:slf4j-android:1.7.14'
|
||||
}
|
||||
|
@ -144,21 +144,6 @@
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.settings.SettingsActivity"
|
||||
android:label="@string/settings_title">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.settings.AccountActivity"
|
||||
android:label="@string/settings_title"
|
||||
android:parentActivityName=".ui.settings.SettingsActivity"
|
||||
tools:ignore="UnusedAttribute">
|
||||
</activity>
|
||||
|
||||
<!-- MemorizingTrustManager -->
|
||||
<activity
|
||||
|
@ -8,17 +8,38 @@
|
||||
|
||||
package at.bitfire.davdroid;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.OnAccountsUpdateListener;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class AccountsChangedReceiver extends BroadcastReceiver {
|
||||
|
||||
protected static final List<OnAccountsUpdateListener> listeners = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
Intent serviceIntent = new Intent(context, DavService.class);
|
||||
serviceIntent.setAction(DavService.ACTION_ACCOUNTS_UPDATED);
|
||||
context.startService(serviceIntent);
|
||||
|
||||
for (OnAccountsUpdateListener listener : listeners)
|
||||
listener.onAccountsUpdated(null);
|
||||
}
|
||||
|
||||
public static void registerListener(OnAccountsUpdateListener listener, boolean callImmediately) {
|
||||
listeners.add(listener);
|
||||
if (callImmediately)
|
||||
listener.onAccountsUpdated(null);
|
||||
}
|
||||
|
||||
public static void unregisterListener(OnAccountsUpdateListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ import android.widget.TextView;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import at.bitfire.davdroid.AccountsChangedReceiver;
|
||||
import at.bitfire.davdroid.Constants;
|
||||
import at.bitfire.davdroid.DavService;
|
||||
import at.bitfire.davdroid.R;
|
||||
@ -131,13 +132,12 @@ public class AccountListFragment extends ListFragment implements LoaderManager.L
|
||||
|
||||
@Override
|
||||
protected void onStartLoading() {
|
||||
Constants.log.debug("AccountListFragment: Start loading");
|
||||
accountManager.addOnAccountsUpdatedListener(this, null, true);
|
||||
AccountsChangedReceiver.registerListener(this, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopLoading() {
|
||||
accountManager.removeOnAccountsUpdatedListener(this);
|
||||
AccountsChangedReceiver.unregisterListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user