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;
setContentView(R.layout.main);
LinphonePreferenceManager.setContext(this);
LinphonePreferenceManager.getInstance(this);
useFirstLoginActivity = getResources().getBoolean(R.bool.useFirstLoginActivity);
useMenuSettings = getResources().getBoolean(R.bool.useMenuSettings);
useMenuAbout = getResources().getBoolean(R.bool.useMenuAbout);

View file

@ -112,7 +112,7 @@ public final class LinphoneManager implements LinphoneCoreListener {
private LinphoneCore mLc;
private int mPhoneOrientation;
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";
ringbackSoundFile = basePath + "/ringback.wav";
lpm = LinphonePreferenceManager.getInstance(c);
mAudioManager = ((AudioManager) c.getSystemService(Context.AUDIO_SERVICE));
mVibrator = (Vibrator) c.getSystemService(Context.VIBRATOR_SERVICE);
mPref = PreferenceManager.getDefaultSharedPreferences(c);

View file

@ -15,7 +15,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
*/
package org.linphone;
import android.content.Context;
@ -25,10 +25,11 @@ import android.preference.PreferenceManager;
public class LinphonePreferenceManager {
private static LinphonePreferenceManager instance;
private static Context c;
private static SharedPreferences p;
private Context c;
private SharedPreferences p;
public LinphonePreferenceManager() {
public LinphonePreferenceManager(Context context) {
c = context.getApplicationContext();
p = PreferenceManager.getDefaultSharedPreferences(c);
}
@ -37,13 +38,10 @@ public class LinphonePreferenceManager {
}
public static final synchronized LinphonePreferenceManager getInstance() {
if (c == null) throw new RuntimeException("need a context");
if (instance == null) instance = new LinphonePreferenceManager();
return instance;
if (instance == null) {
throw new RuntimeException("LinphonePreferenceManager not instanciated");
}
public static final void setContext(Context context) {
c = context.getApplicationContext();
return instance;
}
@ -65,4 +63,12 @@ public class LinphonePreferenceManager {
public int useSpecificAudioModeHack() {
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();
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
PreferenceManager.setDefaultValues(this, R.xml.preferences, true);