In my app, I am trying to run multiple photos through a photo editor (one at a time). I have it set up in a for-loop at the moment, but I feel like it is overloading the photo editor and not actually waiting until the current edit session is over, so I wanted to put a control statement in my for-loop to check if the session was still active.

Is this possible?

有帮助吗?

解决方案

Easier to tell when the current is over than polling to see if it is still active. If you start it with startActivityForResult, your calling activity will be notified when the invoked activity ends.

Have a look at Starting Activities and Getting Results in the Activity docs for an example.

其他提示

You might also want to consider running this in an async task. This will pull your heavy processing away from the UI thread. Async task let's you do progress updates as well.

http://developer.android.com/reference/android/os/AsyncTask.html

public class MainActivity extends ListActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.logo_page);

    // Call async task.
    my_async as = new my_async(this);
    as.execute();

}

--

my_async:

public class my_async extends AsyncTask<Object, Integer, String> {

private parentClass activity;

public my_async (parentClass activity) {
    this.activity = activity;
}

@Override
protected String doInBackground(Object... arg0) {
    // Do stuff

    return "MyString";
}

protected void onPostExecute(String contents) {
    activity.contents = contents;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top