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. Do I have to sign my application for ADC II

Do I have to sign my application before submitting it for ADC II?
Is yes, how do I do that? Do I have to buy some certificate?

2. Why XML to define layouts/components?

My original first post doesn't seem to get approved, so let me try
again. :)

I'm wondering whether other Android newbies than me find the empathy
on XML layout troublesome? I realize we should strive to separate view
from logic and that XML is hip and trendy, but is it really necessary
for these relatively simple Android applications?

XML layouts involves more files and what feels like a lot of
"magic" (type unsafe) properties, and makes samples harder to follow/
type. It also can't be especially efficient to use findViewById
(whether BFS or DFS based) constantly?

It sort of reminds me of the differences between JSF and Wicket, where
the former was designed by people sitting in an ivory tower while the
latter was designed for and by people at the ground, comfortable with
Java. Which also leads me to wonder how come Android uses the old type-
unsafe int enum pattern and also, why fluent-interfaces/method-
chaining isn't used in greater extend?


PS: You might want to fix the URL's to the group charter and FAQ as
they currently go into 404.


3. Widgets: Imageview doesn't support transparency/alpha

4. Debugger doesn't work

5. Widgets: Imageview doesn't support transparency/alpha

6. GLSufaceView rotation performance

7. VerifyError while trying to run Unit tests