jeudi 11 décembre 2014

SharedPreferences Crashes my App on a Tablet but runs perfectly on Android smart Phone

I started Android Development recently and So far it's been good and I'm storing a username in sharedPreferences. I've debugged on my phone (Samsung DUOS) and my app is running smoothly, But when I launch the same app on a Tablet, It Crashes (Freezes and the Crashes). I'd appreciate alot if someone could explain to me why that happens. Tablet and Phone have the same android version (4.4 KitKat) and below is my Code for SharedPreferences section..



new Handler().postDelayed(new Runnable() {
@Override
public void run() {

SharedPreferences mySharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());

if (!mySharedPreferences.contains("url")) {
startActivity(new Intent(getApplicationContext(),
OrbitSettings.class));
finish();
} else {
// for (Config conf : contacts) {
url = mySharedPreferences.getString("url", null);// conf.getUrl();
ns = mySharedPreferences.getString("namespace", null);// conf.getNs();
user = mySharedPreferences.getString("username", null);// conf.getUser();
pswd = mySharedPreferences.getString("passwd", null);// conf.getPswd();
new TestConnection(url, Orbit.this).execute();
}
}
}, 2000); // 2 Seconds


that section is in the onCreate(Bundle savedInstanceState) method and the other Async class is here



class TestConnection extends AsyncTask<Void, Void, Boolean> {

String hostname;
Context ctxt;
boolean isAvailable;

@Override
protected Boolean doInBackground(Void... params) {
try {
InetAddress.getByName(hostname).isReachable(3000);
return true;
} catch (IOException e) {
return false;
}
}

public TestConnection(String host, Context cont) {
super();
this.hostname = host;
this.ctxt = cont;
}

@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result) {
loadData();
startActivity(new Intent(getApplicationContext(),
LoginActivity.class));
finish();
} else {
show("No Route to WebService Found");
finish();
}
}
}


and that's basically it. Any Help is highly appreciated. Thanx in advance!


Aucun commentaire:

Enregistrer un commentaire