startActivityForResult problems

by Geos » Thu, 12 Mar 2009 04:20:10 GMT

Sponsored Links
 Hello All

I've use startActivityForResult as it described in many examples but
it return 0 result code after start new Activity.

In main Activity I use such code for sub activity invocation

                Intent iShowVideo = new Intent(EventHandling.this, 

And such code for getting results.

        protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
                // TODO Auto-generated method stub
                //super.onActivityResult(requestCode, resultCode, data);
                if(requestCode == REQUEST_CODE_SHOW_VIDEO){
                        if(resultCode == RESULT_CANCELED){
                                Toast toast = Toast.makeText(this, 
"onActivityResultCancel: " +
String.valueOf(resultCode), Toast.LENGTH_LONG);
                                Toast toast = Toast.makeText(this, 
"onActivityResult: " +
String.valueOf(resultCode), Toast.LENGTH_LONG);

Here is a part code from ShowVideo activity
        protected void onCreate(Bundle savedInstanceState) {
                // TODO Auto-generated method stub


        Button button = (Button)findViewById(;
        button = (Button)findViewById(;

        //setResult(RESULT_OK, (new Intent()).setAction("Test!"));

    private OnClickListener mOkListener = new OnClickListener()
        public void onClick(View v)
            // To send a result, simply call setResult() before your
            // activity is finished.
            setResult(RESULT_OK, (new Intent()).setAction("Corky!"));

This code should work according many examples. And it should return
RESULT_OK after btnOK clicked but after I click this button it only
closes ShowVideo  Activity.

Please help.

startActivityForResult problems

by droozen » Thu, 12 Mar 2009 08:38:01 GMT

 Not sure if this is your problem, but I do notice you commented out
the super.onActivityResult function in your onActivityResult function.
I don't know all of what the parent method for that function does, but
it's pretty good practice to always call the super method first when
you override a method. It could be doing some setup for you.

I could be way off and that's not what's causing your problem, but
it's a good idea to do it anyway, except for in methods where you know
you shouldn't, like the method for an option item being selected.


Sponsored Links

startActivityForResult problems

by Geos » Thu, 12 Mar 2009 14:48:05 GMT

 I found the problem.
It's a singleInstance application launchMode.


Other Threads

1. Resolution problem while porting Android application on 2430

What resolution is your screen?  What density is it reporting?  What is the
configuration of the emulator in which it is working?  In what way aren't
they fitting?

You probably need to describe your problem a little more for people to be
able to help you?

Dianne Hackborn
Android framework engineer

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.


2. If the bluetooth is build as module not build in, where is better to insmod it

Hi Pavan and Nick,

Thanks for the suggestions! Seems insmod in bluetooth.c is not a good
idea, it do increments the rfkill. I'll put it into init.rc first,
maybe build in finially.

Thanks again!


3. Gears geolocation on G1

4. How to control the SurfaceView's z-order

5. Implications of Using Non Standard Packages

6. Want to learn it to develop app

7. Can I add Linux Driver on the Gphone when I bought it?