returning from an Activity

Common bugs/problems with the Android SDK the Emulator and the ADT-Plugin.

returning from an Activity

Postby jbrohan » Fri Oct 02, 2009 5:38 pm

I found a good example of a camera (Thanks Erado). It has a small Class which extends Activity and the main business is in class PreviewView extends SurfaceView implements SurfaceHolder.Callback, AutoFocusCallback {
etc etc}

In the original example the his Activity is the main. However I would prefer to implement it as an activity called by an Intent, and returning to the onActivityResult in my main Activity.

In other cases I've used this.finish(); to return from an activity started for result. I cannot figure out how to exit this class. It goes round and round nicely taking and storing photos for every click, but I want it to stop after one and return to the main caller to decide what to do next.

Junior Developer
Junior Developer
Posts: 14
Joined: Fri Aug 28, 2009 11:12 am
Location: Montreal


Postby nmc » Fri Oct 02, 2009 6:33 pm

In order to return to the caller of your activity (and return some values to it), you would do something like this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  2.         Intent i = new Intent();
  4.         i.putExtra("SomeName", SomeValue); // e.g. filename of photo?
  6.         setResult(RESULT_OK, i);
  8.         finish();
Parsed in 0.015 seconds, using GeSHi
Senior Developer
Senior Developer
Posts: 154
Joined: Thu Nov 27, 2008 8:30 pm
Location: Germany

Postby Sowmya » Mon Oct 05, 2009 8:40 am

Experienced Developer
Experienced Developer
Posts: 51
Joined: Fri Mar 06, 2009 7:49 am


Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 4 guests