Fix crashes on network change.

This commit is contained in:
Guillaume Beraudo 2011-06-17 16:02:53 +02:00
parent fb8c453098
commit afb615ac9d
5 changed files with 25 additions and 17 deletions

View file

@ -106,7 +106,7 @@ public class LinphoneActivity extends TabActivity {
instance = this; instance = this;
setContentView(R.layout.main); setContentView(R.layout.main);
LinphonePreferenceManager.setContext(this); LinphonePreferenceManager.getInstance(this);
useFirstLoginActivity = getResources().getBoolean(R.bool.useFirstLoginActivity); useFirstLoginActivity = getResources().getBoolean(R.bool.useFirstLoginActivity);
useMenuSettings = getResources().getBoolean(R.bool.useMenuSettings); useMenuSettings = getResources().getBoolean(R.bool.useMenuSettings);
useMenuAbout = getResources().getBoolean(R.bool.useMenuAbout); useMenuAbout = getResources().getBoolean(R.bool.useMenuAbout);

View file

@ -112,7 +112,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
private LinphoneCore mLc; private LinphoneCore mLc;
private int mPhoneOrientation; private int mPhoneOrientation;
private static Transports initialTransports; private static Transports initialTransports;
private static LinphonePreferenceManager lpm = LinphonePreferenceManager.getInstance(); private static LinphonePreferenceManager lpm;
@ -123,6 +123,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
ringSoundFile = basePath + "/oldphone_mono.wav"; ringSoundFile = basePath + "/oldphone_mono.wav";
ringbackSoundFile = basePath + "/ringback.wav"; ringbackSoundFile = basePath + "/ringback.wav";
lpm = LinphonePreferenceManager.getInstance(c);
mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE)); mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE); mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
mPref = PreferenceManager.getDefaultSharedPreferences(c); mPref = PreferenceManager.getDefaultSharedPreferences(c);

View file

@ -25,10 +25,11 @@ import android.preference.PreferenceManager;
public class LinphonePreferenceManager { public class LinphonePreferenceManager {
private static LinphonePreferenceManager instance; private static LinphonePreferenceManager instance;
private static Context c; private Context c;
private static SharedPreferences p; private SharedPreferences p;
public LinphonePreferenceManager() { public LinphonePreferenceManager(Context context) {
c = context.getApplicationContext();
p = PreferenceManager.getDefaultSharedPreferences(c); p = PreferenceManager.getDefaultSharedPreferences(c);
} }
@ -37,13 +38,10 @@ public class LinphonePreferenceManager {
} }
public static final synchronized LinphonePreferenceManager getInstance() { public static final synchronized LinphonePreferenceManager getInstance() {
if (c == null) throw new RuntimeException("need a context"); if (instance == null) {
if (instance == null) instance = new LinphonePreferenceManager(); throw new RuntimeException("LinphonePreferenceManager not instanciated");
return instance;
} }
return instance;
public static final void setContext(Context context) {
c = context.getApplicationContext();
} }
@ -65,4 +63,12 @@ public class LinphonePreferenceManager {
public int useSpecificAudioModeHack() { public int useSpecificAudioModeHack() {
return Integer.parseInt(p.getString(getString(R.string.pref_audio_use_specific_mode_key), "0")); return Integer.parseInt(p.getString(getString(R.string.pref_audio_use_specific_mode_key), "0"));
} }
public static final synchronized LinphonePreferenceManager getInstance(Context c) {
if (instance == null) {
instance = new LinphonePreferenceManager(c.getApplicationContext());
}
return instance;
}
} }

View file

@ -100,7 +100,8 @@ public final class LinphoneService extends Service implements LinphoneServiceLis
super.onCreate(); super.onCreate();
instance = this; instance = this;
LinphonePreferenceManager.setContext(this); // In case restart after a crash . Main in LinphoneActivity // In case restart after a crash. Main in LinphoneActivity
LinphonePreferenceManager.getInstance(this);
// Set default preferences // Set default preferences
PreferenceManager.setDefaultValues(this, R.xml.preferences, true); PreferenceManager.setDefaultValues(this, R.xml.preferences, true);