Created
September 10, 2013 18:19
-
-
Save DiyahM/6513376 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void onLoginSuccess() { | |
MyTwitterApp.getRestClient().getUserCredentials(new JsonHttpResponseHandler () { | |
@Override | |
public void onSuccess(JSONObject jsonUser) { | |
User user = User.fromJson(jsonUser); | |
UserModel currentUser = new UserModel(user.getScreenName(), user.getProfileImageUrl()); | |
currentUser.save(); | |
SharedPreferences pref = getSharedPreferences("myPrefs", MODE_PRIVATE); | |
Editor edit = pref.edit(); | |
edit.putString("current_user", currentUser.getId().toString()); | |
edit.commit(); | |
// this currentUser.getId() returns -1 | |
Log.d("DEBUG","current user id is " + currentUser.getId().toString()); | |
} | |
@Override | |
public void onFailure(Throwable e, JSONObject response) { | |
Log.d("DEBUG", "error" + response.toString()); | |
} | |
}); | |
Log.d("DEBUG", "Login Activity"); | |
Intent i = new Intent(this, TimelineActivity.class); | |
startActivity(i); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.codepath.apps.diyahtwitterapp.models; | |
import com.activeandroid.Model; | |
import com.activeandroid.annotation.Column; | |
import com.activeandroid.annotation.Table; | |
@Table(name = "users") | |
public class UserModel extends Model { | |
@Column(name = "screen_name") | |
private String screenName; | |
@Column(name = "profile_image_url") | |
private String profileImageUrl; | |
public UserModel() { | |
super(); | |
} | |
public UserModel(String screenName, String profileImageUrl) { | |
super(); | |
this.screenName = screenName; | |
this.profileImageUrl = profileImageUrl; | |
} | |
public String getScreenName() { | |
return this.screenName; | |
} | |
public String getProfileImageUrl() { | |
return this.profileImageUrl; | |
} | |
} |
Great! When in doubt, often restarting the emulator and/or uninstalling the app (or wiping the emulator data) will fix a lot of problems. In this case, important to remember that ActiveAndroid only creates the database (and the tables) if there is no database yet created. That means if you run the app, the schema is created and then if you add models or change model attributes, those won't be updated unless the database is wiped (i.e app is uninstalled). Check out https://github.com/pardom/ActiveAndroid/wiki/Schema-migrations for how you can change the schema in situations where wiping the existing database isn't an option.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@nesquena Thanks! That fixed it! I had to delete the app off the emulator.