What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

I want to ask a question on Stack Overflow, but it keeps telling:

Oops! Your question couldn't be submitted because:

Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.

I have checked in the editor that all my code is nicely indented with 4 spaces and I have no idea how to ask that question now.

Here is the question that wont show in SO :

I would like to know if there is any way of getting the activity result some other way than in the onActivityResult() method.

I have written a sample of what I would like to achieve. Button 1 and 2 Is how a normal android app would handle some activity result, and **is it possible to make button 3 from this example to work?** 

This ConfirmActivity class would be called from lots of different places in the code, and handling all those calls in a single function would be really ugly. Getting a result like I showed with button 3 would make the code really clean. I really don't care how much work it goes to making that happen cause once it's done I can just hide that and be happy. I have been thinking of creating threads that would wait for that activity to end and continue work later, or something like that, but I haven't been able to find any way I could make that work. 
If this can be done with a dialog it would be nice as well, I just used an activity here for the example to make it more clear.


Here is the whole code (sorry, if try to explain it with a few line, it seems just to confuse people)


    package com.stack.overflow;

    import android.app.Activity;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    import android.widget.LinearLayout;

    public class StackquestionActivity extends Activity {
        private static final int CONFIRM_ACTIVIY = 0;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            LinearLayout l = new LinearLayout(this);
            Button b1 = new Button(this), b2 = new Button(this), b3 = new Button(this);
            b1.setText("do thing 1");
            b2.setText("something");
            b3.setText("else");
            l.addView(b1);
            l.addView(b2);
            l.addView(b3);
            b1.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    showConfirmActivity(1);
                }
            });
            b2.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    showConfirmActivity(2);
                }
            });
            b3.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    if (showConfirmActivity(3) == 1){ // i would like to continue here after the confirm activity ends
                        //give user what he wants
                    }else {
                        //say you are sorry and send him away
                    }
                }
            });
            setContentView(l);
        }
        private int showConfirmActivity(int act){
            Intent i = new Intent(this, ConfirmActivity.class);
            i.putExtra("request_id", act);
            startActivityForResult(i, CONFIRM_ACTIVIY);
            return 0; // this is where i would like to have a result from the called activity
        }
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            // TODO Auto-generated method stub
            super.onActivityResult(requestCode, resultCode, data);
            if (resultCode == Activity.RESULT_OK && requestCode == CONFIRM_ACTIVIY) {
                int request_id = data.getIntExtra("request_id", 0);
                int ok = data.getIntExtra("ok", 0);
                String response = data.getStringExtra("response");
                Log.v("onActivityResult", "request_id = "+request_id);
                Log.v("onActivityResult", " ok        = "+ok );
                Log.v("onActivityResult", " response  = "+response);
                switch (request_id) {
                    case 1: Log.v("onActivityResult", "continue code from button 1");
                        if (ok==1){
                            //give user what he wants
                        }else {
                            //say you are sorry and send him away
                        }
                        break;
                    case 2: Log.v("onActivityResult", "continue code from button 2");
                        if (ok==1){
                            //give user what he wants
                        }else {
                            //say you are sorry and send him away
                        }
                        break;
                    case 3: Log.v("onActivityResult", "continue code from button 3");
                        break;
                }
            }
        }
    }



ConfirmActivity would be some activity (like a popup or a dialog), for user to interact with confirm a few things. 


here is a rar of the working example  
<http://dl.dropbox.com/u/722768/stackquestion.rar>  
and the individual files  
<http://dl.dropbox.com/u/722768/AndroidManifest.xml>  
<http://dl.dropbox.com/u/722768/StackquestionActivity.java>  
<http://dl.dropbox.com/u/722768/ConfirmActivity.java>  

Thank you for any pointers, and I know that is a lot of code to put there, but I believe it's for a good reason.

share|improve this question
    
I read this question optimistically hoping that we now warned users upon submission of links to dropbox... Bummer –  Cody Gray Aug 1 '11 at 23:59
    
Off topic, but this is a LOT of code to be posting for one question, not even counting the 4 extra files you posted. People don't want to read through mountains of source and pick through external files just to answer your question. Consider narrowing the question and posting just a few lines of code! Also, links to external files are usually okay, but don't expect people to bother reading through them unless they're really curious about your project. –  Justin Morgan Aug 4 '11 at 21:22

1 Answer 1

up vote 13 down vote accepted

This bit:

<http://dl.dropbox.com/u/722768/stackquestion.rar>  
and the individual files  
<http://dl.dropbox.com/u/722768/AndroidManifest.xml>  
<http://dl.dropbox.com/u/722768/StackquestionActivity.java>  
<http://dl.dropbox.com/u/722768/ConfirmActivity.java>  

... is tripping the code warning.


  1. Using an unregistered account, I attempted to open a question with the OP's code. I got these errors:

    Oops! Your question couldn't be submitted because:

    • Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.
    • we're sorry, but as a spam prevention mechanism, new users can only post a maximum of two hyperlinks. Earn more than 10 reputation to post more hyperlinks.
    • Email does not appear to be valid

    (Note that I used a deliberately bogus email to avoid accidentally creating a question.)


  2. Indenting this block, with the Code button:

    <http://dl.dropbox.com/u/722768/stackquestion.rar>  
    and the individual files  
    <http://dl.dropbox.com/u/722768/AndroidManifest.xml>  
    <http://dl.dropbox.com/u/722768/StackquestionActivity.java>  
    <http://dl.dropbox.com/u/722768/ConfirmActivity.java> 
    

    I got:

    Oops! Your question couldn't be submitted because:

    • Email does not appear to be valid


  3. Unindenting the block again yields, again:

    Oops! Your question couldn't be submitted because:

    • Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.
    • we're sorry, but as a spam prevention mechanism, new users can only post a maximum of two hyperlinks. Earn more than 10 reputation to post more hyperlinks.
    • Email does not appear to be valid

Even though that block contains valid URL markdown, perhaps so many of them, in a block formation, is fooling the code sniffer into treating it as HTML?

share|improve this answer
    
Its not malformed, I actually tried both and it even says In most cases, a plain URL will be recognized as such and automatically linked: Visit area51.stackexchange.com regularly! Use angle brackets to force linking: Have you seen <superuser.com>;? –  zidarsk8 Jul 30 '11 at 13:48
7  
The problem aside: I really dislike questions that link to some Dropbox account. @zid, please remember we're Q&A sites not some help forums, so now we expect you to keep the linked files available forever! –  Arjan Jul 30 '11 at 14:00
    
@Arjan, sorry, When I posted the question I thought that it wouldn't work here as well. But it seems to be a problem just with SO, so I removed the link and put the code here to be available with this post. I will be careful not to do that again, but the links in the code will remain cause that is how i wanted to post it. –  zidarsk8 Jul 30 '11 at 14:24
    
The problem is not with the brackets placed before and after the link, because that is the syntax that is reported valid in the help. –  kiamlaluno Jul 30 '11 at 16:23
    
The help button that appears in the text field where you write an answer reports this text, when you click on "Links": Use angle brackets to force linking: Have you seen <http://superuser.com>. It is also what appears in the how to format block. –  kiamlaluno Jul 30 '11 at 16:56
    
@Brock Adams both the "how to format" block and the help for the "Your Answer" field reports that <http://example.com> is correct syntax. I have never used it, but I guess that in some cases it could help. –  kiamlaluno Jul 30 '11 at 17:32
    
@Brock Adams The link you reported links to a page that shows <http://example.com> can be used. Under "Bare URLs," I read: "Force URLs by enclosing them in angle brackets: Have you seen <http://example.com>?" See meta.stackoverflow.com/editing-help#bare-urls. –  kiamlaluno Jul 30 '11 at 17:51
    
@kiamlaluno: So it does. Must be getting tired; skimmed right over that part. –  Awesome Poodles Jul 30 '11 at 18:02
    
@Brock Adams I must admit it is not in the place one would expect it to be, and I remember that part just because I saw it in the "how to format" block. As far as I recall, that block is now only visible to who asks a question; that means that if you normally answer to questions, you could see that block less frequently. –  kiamlaluno Jul 30 '11 at 18:06
    
Well it would seem it's not the whole block, cause I posted comments like that before, and the one that is causing the problems is the .xml file! Thank you guys for helping, but what should I do now. I think this is a weird bug that needs to be fixed. –  zidarsk8 Jul 30 '11 at 20:36
    
Well, this question is now a bug report, one of the devs should get around to it eventually (usually). I don't know if it helps to keep the question unanswered or not. –  Awesome Poodles Jul 31 '11 at 0:53
    
I don't think this is possible to disambiguate from un-code-formatted-XML reliably, and even if it was, it's a total edge case that had other problems. So it's [status-wontfix].. but excellent detective work! –  Jeff Atwood Aug 6 '11 at 4:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .