I am trying to dev my app using the Parse.com lib. When a user login into his account, he goes to the Main activity. At the first time he does that, it is OK. But if he does a logout and then a login again, when he goes to the main activity shows up the error.
I am using a sliding menu that if the user is logged it shows the options: Settings and Logout. Or, shows Login and Sign Up.
Maybe the error is when I am setting the visibilitys of these views. Here is the logCat.
04-17 17:28:03.155: E/AndroidRuntime(14343): FATAL EXCEPTION: main
04-17 17:28:03.155: E/AndroidRuntime(14343): java.lang.RuntimeException: Unable to start activity ComponentInfo{br.com.fitness.legacy.personal/br.com.activities.fitness.legacy.TelaPrincipalLogado}: android.os.NetworkOnMainThreadException
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.ActivityThread.access$600(ActivityThread.java:127)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.os.Handler.dispatchMessage(Handler.java:99)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.os.Looper.loop(Looper.java:137)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.ActivityThread.main(ActivityThread.java:4507)
04-17 17:28:03.155: E/AndroidRuntime(14343): at java.lang.reflect.Method.invokeNative(Native Method)
04-17 17:28:03.155: E/AndroidRuntime(14343): at java.lang.reflect.Method.invoke(Method.java:511)
04-17 17:28:03.155: E/AndroidRuntime(14343): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
04-17 17:28:03.155: E/AndroidRuntime(14343): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
04-17 17:28:03.155: E/AndroidRuntime(14343): at dalvik.system.NativeStart.main(Native Method)
04-17 17:28:03.155: E/AndroidRuntime(14343): Caused by: android.os.NetworkOnMainThreadException
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
04-17 17:28:03.155: E/AndroidRuntime(14343): at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl.close(OpenSSLSocketImpl.java:922)
04-17 17:28:03.155: E/AndroidRuntime(14343): at org.apache.http.impl.SocketHttpClientConnection.close(SocketHttpClientConnection.java:205)
04-17 17:28:03.155: E/AndroidRuntime(14343): at org.apache.http.impl.conn.DefaultClientConnection.close(DefaultClientConnection.java:161)
04-17 17:28:03.155: E/AndroidRuntime(14343): at org.apache.http.impl.conn.tsccm.AbstractConnPool.closeConnection(AbstractConnPool.java:320)
04-17 17:28:03.155: E/AndroidRuntime(14343): at org.apache.http.impl.conn.tsccm.AbstractConnPool.shutdown(AbstractConnPool.java:296)
04-17 17:28:03.155: E/AndroidRuntime(14343): at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.shutdown(ConnPoolByRoute.java:670)
04-17 17:28:03.155: E/AndroidRuntime(14343): at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager.shutdown(ThreadSafeClientConnManager.java:257)
04-17 17:28:03.155: E/AndroidRuntime(14343): at com.parse.ParseRequest.initialize(ParseRequest.java:106)
04-17 17:28:03.155: E/AndroidRuntime(14343): at com.parse.Parse.initialize(Parse.java:108)
04-17 17:28:03.155: E/AndroidRuntime(14343): at br.com.activities.fitness.legacy.TelaPrincipalLogado.onCreate(TelaPrincipalLogado.java:65)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.Activity.performCreate(Activity.java:4465)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
04-17 17:28:03.155: E/AndroidRuntime(14343): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
04-17 17:28:03.155: E/AndroidRuntime(14343): ... 11 more
Sorry for my bad english :/
UPDATE:
I realized that I am already using threads for the Login, Logout and Sign Up. Because the lib provides me the methods below:
ParseUser.logInInBackground(usuario, senha, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
Intent it = new Intent(getApplicationContext(), TelaPrincipal.class);
finish();
startActivity(it);
} else {
Log.e("Erro no login", e.getMessage());
Toast.makeText(getBaseContext(), getString(R.string.tente_novamente), Toast.LENGTH_LONG).show();
}
}
});
Signup method
ParseUser user = new ParseUser();
user.setUsername(usuario);
user.setPassword(senha);
user.setEmail(email);
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
startActivity(new Intent(getApplicationContext(), TelaPrincipal.class));
} else {
Log.e("Erro no Cadastro", e.getMessage());
textViewErro.setText(getString(R.string.tente_novamente));
textViewErro.setVisibility(View.VISIBLE);
}
}
});
So, if the lib do these things to me throws a thread. What I need to do? When a user do loggin ou signup for the first time, everything runs OK. But if he logout and login again the exception shows up. I do not know what I have to do ;/