Android :: One Vs Many Instances Of HttpClient Per Application

Oct 23, 2009

Until recently, our app shared a single Apache HttpClient instance using the ThreadSafeClientConnManager across the whole application. The http client instance was held by a singleton class.

Since I dislike the singleton pattern for its numerous problems, I refactored our API accessor to be a per-thread object, but now for every thread (which mostly means per Activity/Service in our case) a new HttpClient instance is created.

It's not that I have problems with this new approach, but I've read that the Apache folks suggest to only have one instance per app for performance reasons.

Visually, what we did before was this:

HttpClient (thread safe)
|
|
/
/
Activity1...ActivityN

Now, we do this:

Activity1 ... ActivityN
| |
| |
HttpClient1 HttpClientN

How do you guys do this in your applications? If you share one single HttpClient across your app and potentially many concurrent threads, how do you handle access to it?

Android :: One vs many instances of HttpClient per application


Android :: Differentiate Emulator Instances And Real Device Instances

Jul 22, 2009

I need to correctly be able to differentiate between emulator instances. I know it's easily done with real devices. With real devices, you can use getDeviceId or getLine1Number from TelephonyManager. With emulators, all the instances have the same device id, same subscriber id, and same line1 number. Is there a way to differentiate them? Using NetworkInfo, I can call the toString method and I get my ip and the port on the computer. The problem with that is that the port is always different. I would like something more stable. Like when you use "adb devices" in command line. Emulator #1 is almost always "emulator-5556" and emulator#2 is almost always "emulator-5554". Is there a way to get the same info I get from "adb devices" in my code? If not, is it possible to use a command line parameter to force the emulator to use a certain phone number?

View 3 Replies View Related

Android :: How The Use Same Instances When Launching Application Twice

Apr 14, 2009

My app has 4 activities on the stack A->B->C->D (top)

If you press home and re-enter the application, another instance of A is started, so the stack is A->B->C->D->A (top). I know this because when I press BACK, A is popped off and I now see D (instead of going to the Home screen).

What I want is that when the user re-enters the app, they re-enter on the same activity they were in before (D).

CODE:................

View 2 Replies View Related

Android :: How To Use Same Instances When Launching Application Twice

Mar 17, 2009

Is it possible to re-use all the instances of Activities and Services when an application is launched twice. For instance: 1/ I start my application APP1. Some activities are launched and a service is started. 2/ I click "Home" device button 3/ I can see the icon the launch again my application APP1 4/ I click on it and the APP1 is launched twice

I would like to re-use the existing the instances of Activities and Services from the first launch. I guess it is related to "SingleTop" or "SingleTask" but it doesn't seem to work.

View 11 Replies View Related

Android :: Import Org.apache.commons.httpclient.HttpClient Library Error

Jul 2, 2009

I got one blog which interacts with servlets... Link as follows

http://groups.google.com/group/android-developers/browse_thread/threa...

In that program 2 libraries were used..

1---> import org.apache.commons.httpclient.HttpClient; 2---> import org.apache.commons.httpclient.methods.GetMethod;

When i check these libraries in my program, its show error....how to resolve this error?

View 11 Replies View Related

Android : How To Run Multiple Instances Of Same App?

Sep 14, 2010

is it possible to run multiple instances of the same app on android? What I mean if the app does not support multiple identities is it possible to install it twice and configure each instance separately?

View 1 Replies View Related

Android :: Multiple Instances Of Service?

Apr 15, 2010

I would like to do this, let me know if it possible in android?

App1 --> bindService() or startService() to AndroidService1 App2 --> bindService() or startService() to AndroidService1 (same service)

I would like App1 and App2 to get different instances of AndroidService1. Why I want to do this is say App2 doesn't need the service any more & it calls stopService() then App1 should still continue to work with its own instance of service app.

View 2 Replies View Related

Android :: Running Two Instances Of Emulator

Jul 19, 2010

I have written some code in eclipse and I want to run it on two separate Android emulators.

How do I do this when I click "Run"?

I read online and it said I need to do AVD configuration. What is that and how do I do that?

View 2 Replies View Related

Android :: Connect Two Emulator Instances Through Network

Apr 7, 2010

I'm doing a distributed system using Android for my research project.In order to test it, I have connected two emulator instances in the same host machine. However, I need to put these two instances in separate host machines and make them connect through the local network (Wi-fi).I have seen that the emulator runs behind a virtual router, so it seems that I would have to somehow configure such virtual router, in order to forward my requests.

View 2 Replies View Related

Android :: Mulitple Instances Of Pending Intent

Sep 16, 2010

I created a widget that when clicked activates a PendingIntent.The problem is when I have more than one widget on the screen only the latest one will start the PendingIntent.I have read some about a unique request code, but not figured this out.Any ideas how I can have multiple widgets and the PendingIntents work for each?

View 1 Replies View Related

Android :: Launching Multi Instances Of Emulator

Feb 28, 2009

How to i do to launch 2 instances of the Emulator at the same time?

View 2 Replies View Related

Android :: How To Create Multiple Instances Of An Activity

Feb 19, 2010

I want to create multiple instances of an activity in the same process. Should I use FLAG_ACTIVITY_NEW_TASK flag like the code below?

CODE:...............

This code is executed in class A to create another instance of activity A.

This question, will this code create another task? As I understand is a process can only have one task. Does it mean the two activities will exist in different tasks? That's what I want. I want the two activities to be in the same process.

View 1 Replies View Related

Android : How Would You Call A Method From All Instances Of A Class?

Sep 18, 2010

I am writing a basic game engine and have an abstract class that represents any object that can be drawn in the 3D world, however inside this class is an abstract method Render() which I would like called automatically by the engine on each draw phase.

How could I implement this so that every class extending from my abstract class will automatically have Render() called? I am using java, android sdk 2.2, and opengl es

View 4 Replies View Related

Android : How To Create Multiple Instances Of An Activity?

Jul 1, 2010

I was wondering is it possible to create multiple instances of a single Activity in Android?

I currently start my own inCall screen for a Voip Test by using the following code...

This allows me to start the Activity fine. However when I call it for a second it just returns to the Activity already created rather than creating a new Activity and placing it on the stack.

I would like to be able to create the activity multiple times so that I have two or 3 Activities on the stack and the user can switch between them, using Home, Back buttons etc... Is this possible and if so what am I doing wrong?

View 1 Replies View Related

Android :: Starting Two Instances Of Activity With Flag Intent

Jul 18, 2010

When starting two activities of the same class within the same instance using the flag REORDER_TO_FRONT, the new extra information of the second call does not override the first starting activity. Is this the desired behavior? How do retrieve the new extras?

For example: In the StubActivity, I have this code:
Intent i = new Intent(this, A.class);
i.putExtra("foobar",1); startActivity(i);

Activity A is displayed, and then this code is called upon a button press:
new Intent(this, A.class);
i.putExtra("foobar",2);
i.setFlag(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);

Activity A is re-displayed. Now check for the extras: int foobar = getIntent().getExtras().getInt("foobar")
Turns out that foobar = 1

View 2 Replies View Related

Android :: Instances Of MediaPlayer To Play Sounds/video

Jan 18, 2010

Is it possible to have two instances of MediaPlayer to play sounds/ video? How many instances are actually allowed? I can see from the Javadocs that there is a limited amount of instances of MediaPlayer allowed.

View 3 Replies View Related

Android :: How To Pass Class Instances Between Applications In Droid

Mar 18, 2010

I have an application App1 which defines class A and uses instances of this class. What I want to achieve is - after App1 is installed on the device to be able to load App2 which defines and implements class B which is subclass of class A (imported from App1 package); and be able to get an instance of class B in the App1. Class B doesn't add any new interfaces, so using it as class A is ok. But I am not sure how to pass the instance of class B to App1 (preferrably without any user interaction).

Can anyone advise if this is feasible?

View 1 Replies View Related

Android : Multiple Instances Of Included Layout - Namespacing

Jan 12, 2010

I've been attempting to use the <include> tag in some layouts and it seems that these are of limited use because of the flat namespace of the R.id.x approach.

Suppose I have a layout (attribs and xml namespace decl omitted for clarity).

CODE:.......

Now in my java code I have a conundrum. I am not able to identify each individual instance o f the children included layouts root view. In the include tags I can replace the root id with "row1" and "row2" so I can find the individual linear layouts using findViewById

eg:

CODE:.........

However, I can't easily access the two instances of the TextView which are children of row1 and row2 because all I have to play with is the single id "text"

ie:

CODE:..........

In this case, which instance (row1.text or row2.text) does this refer to, both of them, or none?

I guess I would need to use another means of accessing the children of row1 and row2.

View 3 Replies View Related

Android : Way To Create Arrays Of Class Instances In JAVA

May 5, 2010

How to create arrays of class instances in JAVA. code...

View 1 Replies View Related

Android :: Unwanted Automated Creation Of New Instances Of Activity Class

May 11, 2010

I have an activity (called Sender) with the most basic UI, only a button that sends a message when clicked.This works ok, the message is sent but every time a message is sent a new instance of Sender is started on top of the other. If I call sendSMS method three times, three new instances are started. I'm quite new to android so I need some help with this, I only want the same Sender to be on all the time

View 3 Replies View Related

Android :: Can I Save SharedPreferences To File So I Can Have Multiple Instances Of The Prefs?

Jul 19, 2010

I love how SharedPreferences work in android and I would like to know if there is an easy way to save them to another file so I could load a previous instance of the prefs and vice versa. Basically when you load this file, all the preferences would change to how you had it before at once. I want to be able to swap 3 or 4 different versions of the same pref keys in this way. Is there an easy way to do this?

View 1 Replies View Related

Android :: Make Different Instances Of A Widget Behave Different Based On Their AppWidgetId

Oct 5, 2009

I am developing a simple widget which has a couple of buttons in its layout.

Before the widget gets added, the configuration activity is displayed, where the user can choose if the widget makes any sounds when the buttons get pressed or not.

Thus, a user can put two instances of the widget, one where he chose sound to be activated and another where he chose the opposite. However, I can not seem to be able to reproduce the expected behavior (that one reproduces sound and the other doesn't).

The buttons' behavior varies according to the flags specified to the PendingIntent:

- FLAG_UPDATE_CURRENT seems to override the previous intent/setting - no flags (0x00) seems to ignore any intent/setting after the first instance of the widget is put.

What I want to do: I want to be able to configure different instances of the same widget to behave in a different way, according to what the user specified in the configuration activity. I am attempting to do this with the help of the appWidgetId of each instance:

I have tried the following when assigning an action to the click of the button:

CODE:.................

This results in the first widget acting properly (The IDs printed in logcat are as expected) When adding a second widget, however, the first widget starts reporting the second widget's appWidgetId in its onReceive(), when it previously did no such thing. (because of the FLAG_UPDATE_CURRENT, I guess)

How can one make different instances behave in a different way? Is there a way to do this with the help of the appWidgetId?

I have elaborated a widget application for the purpose of debugging this problem which tries to be minimal, while reproducing the (un) desired behavior: http://www.2shared.com/file/8243059/b6519584/IntentTesttar.html

View 5 Replies View Related

Android :: Using HttpClient

Aug 24, 2010

I haven't used the Java HttpClient before and the documentation is confusing. Say I want to send a POST to the URL "https://domain/foo/ bar". I'm accessing a server with an XML API that defines the message to send like this:

code:.........

And the response to expect like this:

code:..........

Now, I can build and parse the portion inside the serverapi tags but I'm not sure how the HttpClient handles the header. If I use the standard code like this:

code:...........

In the area shown as "not sure", should I pre-pend the entire header in front of the xml section, just as it's shown in the server API document or does the client take care of the first line, since it knows the URL?

Is there a way to see exactly what is about to be sent right before I call HttpClient.execute?

As for parsing the response, I believe I can just do this:

code:..........

Or do I need to strip anything off the response content before I start parsing the xml? I took a few stabs at this and it looks like there's some HTTP bookkeeping information at the start of the response content.

View 13 Replies View Related

General :: Is It Possible To Run Two Instances Of Same App

Oct 27, 2011

I've been using a GTD app to keep track of things. My business partner will be joining me soon with an android device. I'm wondering if it is possible to run two instances of this GTD app so that I can have one for personal and one for business. The business one would be so that he can also run the app and we can sync our schedules.

View 6 Replies View Related

Android :: Intent Filters - Prevent Creation Of Multiple Activity Instances?

Feb 16, 2010

I added an intent filter to one of my activities, so that when a user clicks a URL like "www.mysite.com", and if my app is installed, my registered activity can be launched. It works well.

I see that this creates a new instance of my registered activity though, every time a link is clicked. Is there any way to prevent multiple instances from being created - just recycle an existing instance if one already exists?

View 6 Replies View Related

Android :: Best Httpclient Re-use Stategy

Jun 21, 2010

I'm writing a small application which needs httpclient lib, basically to manage the cookie/session automatically. The website I'm targeting needs a valid session, so, between each http call, I need to send the cookie. Httpclient does it well. This is a tv stream application and I have to fetch the channel url, the url has a token parameter and I have to be logged / authenticated / (=> have a valid cookie/sessionid) to fetch the channel url.

I got the first cookie/sessionid with the first connection to the website. The cookie is valid for a certain amount of time, there is no "expires" but I don't know if there is any server cron to cleanup the sessions. I assume I have to "ping" every x secondes to maintain the session valid.

Between each http call, the time could be from 1 sec to several minutes, it depends if the user wants to change the watched tv channel. The http call (to fetch the url) is not made by the UI Thread.

There are several possibilities to manage the httpclient : - a single httpclient static singleton instance accessed by a custom synchronized getClient() on an helper class => when / how to release the http connection ? How to handle that correctly if the user got a phone call / does not use the application for now (unvalidate during onResume, etc)? - Save the cookie (String serialized into SharedPreferences) and create every time a new httpclient instance (then set the cookie to the new instance) => overhead to get the http connection - other ?

View 5 Replies View Related

Android :: Use HTTP/1.0 In HttpClient

May 26, 2010

By default HttpClient use HTTP/1.1 protocol, is there any way to change it to HTTP/1.0?

View 4 Replies View Related

Android :: SSL Certificate HTTPClient

May 28, 2009

I had configure a Tomcat webserver with SSL and client autification. So I need a clienKey.p12 File to visit the site. If I import the key into Firefox, it works fine.

So I tried to develop a Client from "normal" Java. That works:

CODE:..........

Now I try to develope a Client into Android and I am getting crazy....

Here my two Android implementation:

CODE:...........

I always geht the following Exception:

CODE:................

But the key is the same that I use for the "normal" java Client and for the import into firefox. So the key is valid. But it is signed by me... I don't want to sign it by a commercial Company like verisign.

View 2 Replies View Related

Android :: HttpClient And HTTPS?

Apr 8, 2010

I'm new to implementing HTTPS connections in Android. Essentially, I'm trying to connect to a server using the org.apache.http.client.HttpClient. I believe, at some point, I'll need to access the application's keystore in order to authorize my client with a private key. But, for the moment, I'm just trying to connect and see what happens; I keep getting an HTTP/1.1 400 Bad Request error.

I can't seem to make heads or tails of this despite many examples (none of them seem to work for me). My code looks like this (the BODY constant is XmlRPC):

CODE:.......................

View 1 Replies View Related

Android :: Get Web Results From HttpClient?

Jun 19, 2010

For example: Say I searched something on the Walmart homepage. Like this. How would I retrieve the information from the first product listed. Information like product name, price, details, rating, model. And how would I search in the box.

The only way it seems like to me is to replace http://www.walmart.com/search/search-ng.do?

search_constraint=0&ic=48_0&search_query=someProduct&Find.x=0&Find.y=0&Find=Find.

Then replace someProduct with the seach and call it in an HttpClient.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved