Search Results

Search found 34 results on 2 pages for 'stormin986'.

Page 1/2 | 1 2  | Next Page >

  • How to implement a custom AlertDialog View

    - by stormin986
    In the Android docs on AlertDialog, it gives the following instruction and example for setting a custom view in an AlertDialog: If you want to display a more complex view, look up the FrameLayout called "body" and add your view to it: FrameLayout fl = (FrameLayout) findViewById(R.id.body); fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT)); First off, it's pretty obvious that add() is a typo and is meant to be addView(). I'm confused by the first line using R.id.body. It seems that it's the body element of the AlertDialog ... but I can't just enter that in my code b/c it gives a compile error. Where does R.id.body get defined or assigned or whatever?

    Read the article

  • HttpURLConnection: What is the minimum best-practice implementation?

    - by stormin986
    I've come across a lot of HttpURLConnection examples that are nothing more than openConnection(), getInputStream(), and then they just read the buffer and are done. It's simple but seems like it's not the best implementation ... it handles no problems. I don't yet know much about http, so I keep thinking I have everything covered until a new problem arises. I'm currently experiencing a similar problem to this one. Most times I try to read the same resource a second time (from a different HttpURLConnection object, after I .disconnect()'ed the previous one), the response code returns as -1 (but no exception is thrown!!). Before I knew to check the response code, I was baffled since I was throwing no exceptions. So, is there a minimum 'best practice' HttpURLConnection implementation? What are notable exceptions to handle? Request code checking? Any other error checks? What connection parameters do and don't need to be set (like doInput / doOutput, are these even necessary? Some examples have em, some don't). Etc. I realize this is kind of a broad question but I think it has potential to be a very useful resource if many of the common use cases and FAQs are addressed in one central place. This seems like the kind of thing a community wiki would be good for...

    Read the article

  • Reading HttpURLConnection InputStream - manual buffer or BufferedInputStream?

    - by stormin986
    When reading the InputStream of an HttpURLConnection, is there any reason to use one of the following over the other? I've seen both used in examples. Manual Buffer: while ((length = inputStream.read(buffer)) > 0) { os.write(buf, 0, ret); } BufferedInputStream is = http.getInputStream(); bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append(current); } EDIT I'm still new to HTTP in general but one consideration that comes to mind is that if I am using a persistent HTTP connection, I can't just read until the input stream is empty right? In that case, wouldn't I need to read the message length and just read the input stream for that length? And similarly, if NOT using a persistent connection, is the code I included 100% good to go in terms of reading the stream properly?

    Read the article

  • TabWidget Activity Handling - Does it Create a New Activity EVERY Time?

    - by stormin986
    When a TabWidget is using intents to designate the target Activity for each tab, is there any special handling of those Activities on the Activity Stack outside of the default operation? For Instance, if my app has tabs A, B, and C, and I click them in this order––A, B, A, C, A, B––how will the Activity stack change? My understanding of the default operation, if startActivity() is called each time on the intent, would have the Stack keep loading up new instances of the activities: A, AB, ABA, ABAC, ABACA, ABACAB It's hard to believe that's how it works though... Seems like it would be a waste of resources and could be endless. Can anyone tell me how this will actually work?

    Read the article

  • HttpURLConnection: Is it necessary to call connect()?

    - by stormin986
    Many examples I've seen don't explicitly call connect(). Instead they just use getInputStream() or getResponseCode(). I'm assuming all of these HttpURLConnection methods that require a connection just call connect() themselves? Are there any cases where connect() must be explicitly called for an HttpURLConnection?

    Read the article

  • Hide Soft Keyboard Not Working ...

    - by stormin986
    I'm developing on the Droid Incredible (and have tested on a 1.5 AVD Emulator as well), and one of the tabs in my tab widget consists of a listview and a row with an EditText and a Send button (for a chat feature). I am using the following to close the soft keyboard once I click Send, but it's not working. This is identical to code I've found elsewhere that people have upvoted as correct. See anything I'm missing? // in Button's onClick(): EditText chatTextBox = (EditText) findViewById(R.id.chat_entry); // Handle button click ... chatTextBox.setText(""); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromInputMethod(chatTextBox.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); I also tried changing the flag to 0. No luck. Anyone know what's up??

    Read the article

  • Simplest Way to Process Basic HTTPS GET File Requests?

    - by stormin986
    All I need to do is download some basic text-based and image files from a web server that has a self-signed SSL certificate. I have been trying to figure out how to use HttpClient to do this, but getting the SSL to work is a nightmare that seems to be way too much trouble for such a simple task. Is there a better way to perform these file downloads? Perhaps through a WebView or Browser feature? Reinventing the wheel of making a simple HTTPS GET request is a major pain, and is significantly holding up my development schedule.

    Read the article

  • Best Way to Include Debug Code?

    - by stormin986
    I am programming Android applications, and the best way here may or may not be the same as Java in general. I simply want to be able to set a debug flag that will only execute certain portions of code when it's set to true––equiv to C++ setting a preprocessor #define DEBUG and using #ifdef DEBUG. Is there an accepted or best way to accomplish this in Java? Right now I'm just going to set a variable in my Application object, but I don't imagine this is the best way.

    Read the article

  • HttpURLConnection: What's the deal with having to read the whole response?

    - by stormin986
    My current problem is very similar to this one. I have a downloadFile(URL) function that creates a new HttpURLConnection, opens it, reads it, returns the results. When I call this function on the same URL multiple times, the second time around it almost always returns a response code of -1 (But throws no exception!!!). The top answer in that question is very helpful, but there are a few things I'm trying to understand. So, if setting http.keepAlive to false solves the problem, it indicates what exactly? That the server is responding in a way that violates the http protocol? Or more likely, my code is violating the protocol in some way? What will the trace tell me? What should I look for? And what's the deal with this: You need to read everything from error stream. Otherwise, it's going to confuse next connection and that's the cause of -1. Does this mean if the response is some type of error (which would be what response code(s)?), the stream HAS to be fully read? Also, every time I am attempting an http request I am basically creating a new connection, and then disconnect()ing it at the end. However, in my case I'm not getting a 401 or whatever. It's always a 200. But my second connection almost always fails. Does this mean there's some other data I should be reading that I'm not (in a similar manner that the error stream must be fully read)? Please help shed some light on this? I feel like there's some fundamental http protocol understanding I'm missing.

    Read the article

  • Does pressing Back always cause Activity to finish()?

    - by stormin986
    I've heard that pressing the back button will essentially cause the current Activity to finish(). Is this always the case? Seems like it would be with the way it pops the Activity off the stack. The one situation I'm not so sure about is when the root Activity in a Task has back pressed. I'm currently experiencing a very weird effect, described as follows: On loading my application, the first Activity is for initialization, and once it finishes, it calls my main Activity (a TabActivity). This first init activity has android:noHistory="true" set in the Manifest so pressing Back from my main Activity won't go back to that. It goes to the Launcher. When I click on my App in the Launcher a second time, the initialization activity loads again, and loads the main Activity when done. Almost immediately after, it loads a second instance of my main Activity. But ONLY after the Application has already been run once, and was exited by pressing BACK from the main Activity. It does it every subsequent time until I force quit the app or load a new version from the IDE. Based on this, I am suspecting some kind of Activity instance is lying around and being reused, since it only happens on the second+ time I run the application (and exit with BACK -- using HOME just returns to the last state of the app, no big deal). Anyone have any thoughts??

    Read the article

  • AsyncTask and onDestroy...

    - by stormin986
    I have an activity initiate a few AsyncTask downloads. After two of the three finish, it issues an Intent to load the next activity while still finishing up the last download. Obviously in onDestroy() i will call cancel() on all AsyncTask objects. If the OS tries to destroy my activity after the next activity starts, it will call and begin executing onDestroy in the apps UI thread, right? It won't wait for that AsyncTask to complete, correct? In all cases it will ultimately call onDestroy(), in turn canceling all AsyncTasks?

    Read the article

  • Android Template Application?

    - by stormin986
    I have built an application that I want to use as the foundation for a few other variants. The variants will come from assets / resource files and a unique AndroidManifest.xml. However, I want to be able to leave all the application code alone (modifying the package of all my classes, etc). I'm having a hard time figuring out how to do so. My first thought was to simply have my main application in its own package, and then specify the specific application package in the manifest. However, this gives me issues with the generated R.java class, since it is generated to be in the main application's package. Anyone have any thoughts on how to accomplish this? To have a code baseline, and the application variants happen in resources/assets and the manifest?

    Read the article

  • KeyStore, HttpClient, and HTTPS: Can someone explain this code to me?

    - by stormin986
    I'm trying to understand what's going on in this code. KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream = new FileInputStream(new File("my.keystore")); try { trustStore.load(instream, "nopassword".toCharArray()); } finally { instream.close(); } SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore); Scheme sch = new Scheme("https", socketFactory, 443); httpclient.getConnectionManager().getSchemeRegistry().register(sch); My Questions: trustStore.load(instream, "nopassword".toCharArray()); is doing what exactly? From reading the documentation load() will load KeyStore data from an input stream (which is just an empty file we just created), using some arbitrary "nopassword". Why not just load it with null as the InputStream parameter and an empty string as the password field? And then what is happening when this empty KeyStore is being passed to the SSLSocketFactory constructor? What's the result of such an operation? Or -- is this simply an example where in a real application you would have to actually put a reference to an existing keystore file / password?

    Read the article

  • What happens on Activity.finish() with AsyncTask still running in background?

    - by stormin986
    What happens on Activity.finish() with an AsyncTask still running in background? Does it just pop the Activity off the Activity Stack, but wait to destroy the Activity object until the AsyncTask fully completes (since the AsyncTask is an inner class of my Activity)? Also, would it act any differently if the AsyncTask were a public, non-inner class that held no references to the instance of the Activity?

    Read the article

  • HTTPS with Self-Signed Certificate Issues... Solution or better way?

    - by stormin986
    All I need to do is download some basic text-based and image files from a web server that has a self-signed SSL certificate. I have been trying to figure out how to use HttpClient to do this, but getting the SSL to work is a nightmare that seems to be way too much trouble for such a simple task. Is there a better way to perform these file downloads? Perhaps through a WebView or Browser feature? Reinventing the wheel of making a simple HTTPS GET request is a major pain, and is significantly holding up my development schedule. ** Updated title to more accurately reflect question / solution **

    Read the article

  • Loading a Browser Page in the Background

    - by stormin986
    I have a tabbed interface (one activity per tab) where one tab will be a browser view displaying a webpage. The application loads in a different activity / view, but I want it to begin to download the webpage in the background as soon as the app launches, before the user ever clicks on that tab and initiates that activity. How can I do this? Thanks! -S

    Read the article

  • Issue calling superclass method in subclass constructor

    - by stormin986
    I get a NullPointerException calling a Superclass Method in Subclass Inner Class Constructor... What's the Deal? In my application's main class (subclass of Application), I have a public inner class that simply contains 3 public string objects. In the parent class I declare an object of that inner class. public class MainApplication extends Application { public class Data { public String x; public String y; public String z; } private Data data; MainApplication() { data = new Data() data.x = SuperClassMethod(); } } After I instantiate the object in the constructor, I get a runtime error when I try to assign a value in the inner class with a superclass method. Any idea what's up here?? Can you not call superclass methods in the subclass constructor? ** Edit ** Original question was about inner class member assignment in outer class constructor. Turned out the issue was with calling a superclass method in the class's constructor. It was giving me a null pointer exception. Thus, the question has changed.

    Read the article

  • Android: Quitting the Looper?

    - by stormin986
    I have a thread I use to periodically update the data in my Activity. I create the thread and start a looper for using a handler with postDelay(). In onDestroy() for my activity, I call removeCallbacks() on my handler. Should I then call handler.getLooper().quit()? Or not worry about it and let the OS deal with it? Or would it just run forever then, consuming CPU cycles?

    Read the article

  • Reading HttpURLConnection InputStream - manual buffer or BufferedInputStream?

    - by stormin986
    When reading the InputStream of an HttpURLConnection, is there any reason to use one of the following over the other? I've seen both used in examples. Manual Buffer: while ((length = inputStream.read(buffer)) > 0) { os.write(buf, 0, ret); } BufferedInputStream is = http.getInputStream(); bis = new BufferedInputStream(is); ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append(current); } EDIT I'm still new to HTTP in general but one consideration that comes to mind is that if I am using a persistent HTTP connection, I can't just read until the input stream is empty right? In that case, wouldn't I need to read the message length and just read the input stream for that length? And similarly, if NOT using a persistent connection, is the code I included 100% good to go in terms of reading the stream properly?

    Read the article

  • Handling Application Logic in Multiple AsyncTask onPostExecute()s

    - by stormin986
    I have three simultaneous instances of an AsyncTask for download three files. When two particular ones finish, at the end of onPostExecute() I check a flag set by each, and if both are true, I call startActivity() for the next Activity. I am currently seeing the activity called twice, or something that resembles this type of behavior. Since the screen does that 'swipe left' kind of transition to the next activity, it sometimes does it twice (and when I hit back, it goes back to the same activity). It's obvious two versions of the activity that SHOULD only get called once are being put on the Activity stack. The only way I can find that this is possible is if both AsyncTasks' onPostExecute() executed SO simultaneously that they were virtually running the same lines at the same time, since I set the 'itemXdownloaded' flag to true right before I check for both and call startActivity(). But this is happening enough that it's very hard for me to believe that both downloads are finishing precisely at the same time and having their onPostExecute()s so close together... Any thoughts on what could be going on here? General gist of code (details removed, ignore any syntactical errors I may have edited in): // In onPostExecute() switch (downloadID) { case DL1: dl1complete = true; break; case DL2: dl2complete = true; break; case DL3: dl3complete = true; break; } // If 1 and 2 are done, move on (DL3 still going in background) if ( downloadID != DL3 && dl1complete && dl2complete) { ParentClass.this.startActivity(new Intent(ParentClass.this, NextActivity.class)); }

    Read the article

  • AsyncTask Threading Rule - Can it really only be used once?

    - by stormin986
    In the documentation on AsyncTask it gives the following as a rule related to threading: The task can be executed only once (an exception will be thrown if a second execution is attempted.) All this means is that you have to create a new instance of the class every time you want to use it, right? In other words, it must be done like this: new DownloadFilesTask().execute(url1, url2, url3); new DownloadFilesTask().execute(url4, url5, url6); Or conversely, you can NOT do the following: DownloadFilesTask dfTask = new DownloadFilesTask(); dfTask().execute(url1, url2, url3); dfTask().execute(url4, url5, url6); Can someone verify this is an accurate interpretation? I realize I pretty much just answered this for myself as I was typing this out... But it wasn't immediately obvious to me so I think this would be useful to have posted nonetheless.

    Read the article

  • Error Instantiating an Inner Class in Parent's Constructor...

    - by stormin986
    In my application's main class (subclass of Application), I have a public inner class that simply contains 3 public string objects. In the parent class I declare an object of that inner class. public class MainApplication extends Application { public class Data { public String x; public String y; public String z; } private Data data; MainApplication() { data = new Data() data.x = "String"; } } After I instantiate the object in the constructor, I get a runtime error when I try to assign any of the inner class object's variables. Any idea what's up here??

    Read the article

  • Updating Activity UI from Different Activity Method?

    - by stormin986
    I have a tab widget where one of the tabs is a chat-type feature. I want to update the chat data at an interval (variable depending on whether the chat tab is active or not). The best approach seemed to be using an AsyncTask in my main TabActivity class, as that would avoid any issues of the chat activity being destroyed while in the background, while an AsyncTask was running. I wanted to ensure that the Activity isn't destroyed and recreated, thus causing my AsyncTask to be unable to modify the actual active Activity's data. However, now that my AsyncTask is in the TabActivity activity, I don't have a direct way to call my Chat's ListAdapter notifyDataSetChanged() from my onPostExecute() method anymore. Is there a way to get a reference to a given Tab's current Activity from the TabHost/TabActivity? Or, alternatively, can I assume my chat activity will never be destroyed as a child activity of the TabActivity activity (well, never destroyed while the TabActivity is active at least), and then just put the AsyncTask in the Chat Activity?

    Read the article

  • Same Activity called twice... Issue with Multiple AsyncTasks?

    - by stormin986
    I have three simultaneous instances of an AsyncTask for download three files. When two particular ones finish, at the end of onPostExecute() I check a flag set by each, and if both are true, I call startActivity() for the next Activity. I am currently seeing the activity called twice, or something that resembles this type of behavior. Since the screen does that 'swipe left' kind of transition to the next activity, it sometimes does it twice (and when I hit back, it goes back to the same activity). It's obvious two versions of the activity that SHOULD only get called once are being put on the Activity stack. Could this be from both onPostExecute()s executing simultaneously and both checking the flags each other set at the exact same time? This seems extremely unlikely since two processes would have to be running line-by-line in parallel... *EDIT* A lot removed from this question since I was way off in what I thought was wrong. Nonetheless I found the answer here quite useful, so I have edited the question to reflect the useful parts.

    Read the article

1 2  | Next Page >