Question

If I use asynch call the application function but not like I want. If I use the synch call the application doesn't function and crashes when I launch it. (Unable to resume activity: NetworkOnMainThreadException) Why??

private void makeFBRequest(final Session session) {
           Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {
            @Override
            public void onCompleted(GraphUser user, Response response) {
               if (session == Session.getActiveSession()) {
                    if (user != null) {
                       Profile.name = user.getFirstName();
                       Profile.surname = user.getLastName();
                       Profile.email = (String) user.asMap().get("email");
                }
            }   
        });     
        //request.executeAsync();   
          request.executeAndWait();
    }  
Was it helpful?

Solution

I resolved that problem introducing these lines before the call.

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top