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

Hello
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.

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

Top

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
  1.  
  2.         Intent i = new Intent();
  3.  
  4.         i.putExtra("SomeName", SomeValue); // e.g. filename of photo?
  5.  
  6.         setResult(RESULT_OK, i);
  7.  
  8.         finish();
  9.  
  10.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
nmc
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

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

Top

Return to SDK/ADT/Emulator Problems

Who is online

Users browsing this forum: No registered users and 4 guests