Reputation: 163
I'm using Parse with my Android app, and my code looks like this:
public class SignupActivity extends Activity {
//Collect signup data
User.signupInBackground(data);
}
public class User{
//User methods, constructors, etc
public static void signup(data){
ParseUser pUser = new ParseUser();
//Build data into pUser
pUser.signUpInBackground(new SignUpCallback() {
public void done(ParseException e){
if (e!=null){
Log.v("Signup",e.toString());
}
}
});
So the question is, how do I notify my activity when the signUpInBackground process is complete? I can't have SignupActivity implement SignUpCallback because it's an abstract class and I have to extend Activity.
Ultimately, what I'm trying to do is display a dialog box or waiting animation, and then get rid of it when the background thread is done. Alternatively, the background thread could launch an activity. The problem with this is that the User class and the anonymous inner class don't have their own Context, so they can't start activities.
I'm fairly new at this, so thanks for your help.
Upvotes: 0
Views: 373
Reputation: 234847
Several approaches might work given your current code structure.
Handler
in SignupActivity
and pass that to the User
so it has a way of interacting with the activity.SignUpCallback
an interface instead of an abstract class.SignUpCallback
in your SignupActivity
class; it will have access to the methods of SignupActivity
.I'm assuming that signUpInBackground
is executing on a worker thread and that the callback is invoked from that thread. If that's correct, then in all cases you will need to interact with SignupActivity
through a Handler
. Thus, I'd suggest method #1 unless the other approaches allow for cleaner code.
Upvotes: 2