Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3802702
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T14:14:55+00:00 2026-05-19T14:14:55+00:00

I am fairly new to Android and I like to have an inputstream be

  • 0

I am fairly new to Android and I like to have an inputstream be transferred from one class to another.
Basically, I am trying to get a geocoded location to be sent to a server and a response to be sent to the other class for parsing.

here is a snippet of code I have so far for the httppost and inputstream response:

Location1.java

private void updateWithNewLocation(Location location) {
  if (location != null) {
    double lat = location.getLatitude();
    String lat1 = Double.toString(lat);
    double lng = location.getLongitude();
    String lng1 = Double.toString(lng);

 HttpClient httpclient = new DefaultHttpClient();
 HttpPost httppost = new HttpPost("http://...");

 try {

     List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);

nameValuePairs.add(new BasicNameValuePair(“lat”, lat1));
nameValuePairs.add(new BasicNameValuePair(“lng”, lng1));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

     HttpResponse response = httpclient.execute(httppost);
 InputStream is = response.getEntity().getContent();

BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(20);

int current = 0;  
while((current = bis.read()) != -1){  
 baf.append((byte)current);  
}  

Here is a snippet from the other class I want to have the inputstream parsed in… There already was an inputsream in this class and I was trying to figure out how to replace it with the other stream from the other class.

parser1.java

       //I already have an inputstream here and this is where I want to inject the other class inputstream

          InputStream in = httpConnection.getInputStream(); 
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
   DocumentBuilder db = dbf.newDocumentBuilder();

   // parse the feed
   Document dom = db.parse(in);      
   Element docEle = dom.getDocumentElement(); ...

Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T14:14:56+00:00Added an answer on May 19, 2026 at 2:14 pm

    I think this is more a Java question than an Android one. Can’t you just make your existing updateWithNewLocation() method public and return an InputStream rather than void? Something like:

    Location1.java

    public static InputStream updateWithNewLocation(Location location) {
        InputStream result = null;
        if (location != null) {
            double lat = location.getLatitude();
            String lat1 = Double.toString(lat);
            double lng = location.getLongitude();
            String lng1 = Double.toString(lng);
    
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://...");
    
            try {
    
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("lat", lat1));
                nameValuePairs.add(new BasicNameValuePair("lng", lng1));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    
                HttpResponse response = httpclient.execute(httppost);
                result = response.getEntity().getContent();
            } catch(Exception e) {
                //error handling
            }
        return result;
    }
    

    parser1.java

    ...
    InputStream in = Location1.updateWithNewLocation(location)
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    
    // parse the feed
    Document dom = db.parse(in);      
    Element docEle = dom.getDocumentElement();
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another question about my implementation. I am fairly new to java/android coming from a
I'm fairly new to Android, and am trying to build a custom component in
I am fairly new to Android programming and was wondering how I can get
Ok, im fairly new to android but i have managed to teach myself the
I'm fairly new to the Android platform and was wondering if I could get
Everything will be coming from JSON objects. I'm fairly new to android layouts, what
I have just began opengl programming in android and i am fairly new to
I have a fairly simple android app, it gets protobuf data from a web
I'm fairly new to Android and have been toying around with Canvas. I'm attempting
I'm fairly new to Android, but have done lots of Java/JSP development and HTML

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.