You will have quite a few problems with this setting, but here's how you can get started:
You will need to include in the project any actions that do nothing but start the activity from which you want to get the result, and save it in a globally accessible storage (for example, a singleton or static field).
class Pojo { static final ConditionVariable gate = new ConditionVariable(); static int result; int m(Context context) { context.startActivity(new Intent(context, ForwarderActivity.class)); gate.block(); return result; } } class ForwarderActivity extends Activity { private boolean started = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (!started) { started = true; startActivityForResult(new Intent("ContactsProvider"), 1); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { Pojo.result = resultCode; Pojo.gate.open(); } }
However, there are a couple of problems. Just like your POJO method cannot be called from the main (UI) thread, since you need to convert the asynchronous call (startActivityForResult ()) to the synchronous (Pojo.m ()) and the activity that you want to receive from will be started mainly stream, so you cannot block it in Pojo.m () ...
Anyway, the code doesn't work, but you can see where to go if you really need to stick with this setting. But you really should try to find other ways to collect data, such as a content provider.
Szabolcs berecz
source share