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();

 protected void onCreate(Bundle savedInstanceState) {

 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);
 else {
 String currentUserId = Backendless.UserService.loggedInUser();
 Backendless.UserService.findById(currentUserId, new AsyncCallback<BackendlessUser>() {

public void handleResponse(BackendlessUser user) {
currentUser = user;
 // shows email correct.......

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


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.