trying to access CurrentUser, What's wrong with my code

Here is my full code


public class MainActivity extends Activity {



Context context = this;


BackendlessUser currentUser = new BackendlessUser();



 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);



 Backendless.initApp(context, "XXX", "XXX", "XX" );



 String userToken = UserTokenStorageFactory.instance().getStorage().get();
 
 if(!(userToken != null && !userToken.equals( "" )))
 { // user login is available, skip the login activity/login form 
 Intent intent = new Intent(context, LoginActivity.class);
 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
 startActivity(intent);
 }
 else {
 String currentUserId = Backendless.UserService.loggedInUser();
 Backendless.UserService.findById(currentUserId, new AsyncCallback<BackendlessUser>() {

@Override
public void handleResponse(BackendlessUser user) {
Backendless.UserService.setCurrentUser(user);
currentUser = user;
 // shows email correct.......


 Helper.showSuccessDialog(context, currentUser.getEmail());



}

@Override
public void handleFault(BackendlessFault fault) {
Helper.showErrorDialog(context, fault.getMessage());
}
}); 
 } // else ends
 // shows empty toast.........


 Toast.makeText(context, currentUser.getEmail(), Toast.LENGTH_LONG).show();


 } // onCreate ends..........

What is wrong here, because I want to save some data in user’s table which i need to access from activity afterwards but it is not working from me.

Things I have tried,

currentUser kept undefined, < same result,
currentUser declared and defined inside onCreate()

Thing I encountered during one of above,

if user was not logged in (i.e 1st use), then works, after killing and restarting application gives error a strange ANR and no exception in logcat

Any clue what wrong?
Thanks a lot

Hi Muhammad,

Finding a problem in your code is not free, according to out Support Policy. The sample you can get on Code Generation console tab contains a similar code, you can take a look at it there.