I'm not here to judge if it is good or not, but if you really need activity to wait for sub-activity, you can try this approach:
- define an object (lock) by which two actions are synchronized; it can (should) also work as an object for exchanging data between these two actions and, therefore, should be defined as static
- in parent activity, run the async task (since the main thread of the user interface cannot be pending)
- in an asynchronous task, run your sub-asset.
- asynchronous task is waiting for a lock until notification
- the sub-activity does everything it needs and notifies the waiting thread at completion
I did a similar thing in my application, and IMHO had a good reason for this (in order not to bother the user with the login screen when starting or resuming the application, the application tries to reuse the credentials stored in a secure place, and only so Yes, in In principle, any activity in my application can be "paused" and waiting until the user provides the correct credentials in the login activity, which ends the login screen, and the application continues exactly where it was obtained is suspended (the parent activity).
In the code, it will be something like this:
ParentActivity:
public class ParentActivity extends Activity { private static final String TAG = ParentActivity.class.getSimpleName(); public static class Lock { private boolean condition; public boolean conditionMet() { return condition; } public void setCondition(boolean condition) { this.condition = condition; } } public static final Lock LOCK = new Lock(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.parent_layout);
ChildActivity:
public class ChildActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.child_layout);
pepan Feb 25 '15 at 10:35 2015-02-25 10:35
source share