Example #1
0
  protected void onStop() {
    super.onStop();
    App42API.initialize(
        getApplicationContext(),
        "33febecb03a579e972755eccde307dd94a279b5cfe348f845b8762f8e3feb2d6",
        "b5be405b4e76d40a94cdc01250311205b5a7c7b2dc4d003714f24d0df3e219f8");

    final UserService userService = App42API.buildUserService();
    App42API.setOfflineStorage(true);
    String username = mGameSettings.getString(GAME_PREFERENCES_USERNAME, null);
    String schl = mGameSettings.getString(GAME_PREFERENCES_SCHOOL, null);
    App42API.setLoggedInUser(username);
    String p = mGameSettings.getString(GAME_PREFERENCES_PASSWORD, null);
    String strEmailToSave = mGameSettings.getString(GAME_PREFERENCES_EMAIL, null);
    String pwd = p;
    String emailId = strEmailToSave;
    /* This will create user in App42 cloud and will return created User
    object in onSuccess callback method */
    userService.createUser(
        username,
        pwd,
        emailId,
        new App42CallBack() {
          public void onSuccess(Object response) {
            User user = (User) response;
            System.out.println("userName is " + user.getUserName());
            System.out.println("emailId is " + user.getEmail());
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });

    User userObj = new User();
    userObj.setUserName(username);
    Profile profile = userObj.new Profile();
    Date date = new Date(); /* returns the current date object.User can set any date */
    profile.setFirstName(username);
    profile.setLine1(schl);
    /* Following will create user profile and returns User object
    which has profile object inside in onSuccess callback method */
    userService.createOrUpdateProfile(
        userObj,
        new App42CallBack() {
          public void onSuccess(Object response) {
            User user = (User) response;
            System.out.println("userName is " + user.getUserName());
            System.out.println("School  is " + user.getProfile().getLine1());
          }

          public void onException(Exception ex) {
            System.out.println("Exception Message" + ex.getMessage());
          }
        });
    Toast.makeText(getApplicationContext(), "User Settings Saved", Toast.LENGTH_SHORT).show();
    UtilSettings.this.finish();
  }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   super.requestWindowFeature(Window.FEATURE_NO_TITLE);
   setContentView(R.layout.activity_main);
   responseTv = ((TextView) findViewById(R.id.response_msg));
   edUserName = ((EditText) findViewById(R.id.uname));
   edMessage = ((EditText) findViewById(R.id.message));
   buildSpinnerLayout();
   App42API.initialize(this, "Your API Key", "Your Secret Key");
   App42Log.setDebug(true);
   // UserName You want to register on App42
   App42API.setLoggedInUser("YourUserName");
 }