0

Im working with Android 2.1, RoboGuice 1.1 and Guice 2.0 (without aop).
My app has a background thread that gets started in the onCreate method of the Activity which connects to a server and might need the user to provide credentials for logging in.

At first I found the PopupWindow in the API but I read in this post that it shouldn't be used for that.

So I tried to inject my Activity into my background thread and to open a Dialog in a Runnable passed to Activity.runOnUIThread(Runnable r) but unfortunately roboguice is creating a new instance of my activity when injecting it into my background thread.

I now assume the correct way of implementing a Login-Dialog would be to send an Intent to my activity and let it show the Dialog. Furthermore I assume that the Activity needs to send an Intent (containing the credentials) back to the background thread.
Is this correct or is there a more elegant way of doing that?

In this post I found how to register a receiver for the Intent. But on which Activity instance should I call registerReceiver within the background thread?

Best regards

Community
  • 1
  • 1
Marc-Christian Schulze
  • 3,154
  • 3
  • 35
  • 45

1 Answers1

0

I would suggest to create an inner class in the activity that uses RoboAsyncTask and basically has access to the activity. That works well for me. If you need to be able to login from different activities you make it a top level class and pass the fragment or activity instance into the async task constructor and do the ui updates in onSuccess.

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123