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 8063341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:59:52+00:00 2026-06-05T10:59:52+00:00

there’s not getapplication() in classes extend fragement and in asynchtask , I only have

  • 0

there’s not getapplication() in classes extend fragement and in asynchtask , I only have context how to get application

because I need to call global variable

GlobalVariables appState = (GlobalVariables) getApplication();

Encounter EncounterObject = appState.encounters.get(position);

in either of those classes

ackage com.appnetics;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.app.Application;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

/*
 * onPreExecute()- create the progress bar dialog. 
 * doInBackground()- start the new thread.
 * onPostExecute()- dismiss the progress bar dialog.
 * */
  class EncounterBackgroundWorker extends AsyncTask<Void, Void, Void> {

      ProgressDialog connectionProgressDialog;


         private Context context;


         public EncounterBackgroundWorker(Context Context  )
         {
           this.context=Context;

          }


      @Override
      protected void onPreExecute() {


          connectionProgressDialog = new ProgressDialog(context);
          connectionProgressDialog.setCancelable(false);
          connectionProgressDialog.setCanceledOnTouchOutside(false);
          connectionProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
          connectionProgressDialog.setMessage("Uploading Leads...");
          connectionProgressDialog.show();
      }
      @Override
      protected Void doInBackground(Void... params) {
        try {
            // Call the Encounter web service 
            String Result = null;

            StringBuilder URL = new StringBuilder();

            URL.append("http://163.121.237.103/ali");//this.URL.getText()
            URL.append("/Service.svc/ReturnEncounter");

            /*URL.append("http://192.168.254.31:90/Service.svc/Login/");
            URL.append(username.getText());
            URL.append("/");
            URL.append(password.getText());

            finalResult.setText(  URL.toString() ) ;*/
            ///////////////////////////// 
            HttpClient client = new DefaultHttpClient();
            HttpGet httpGet = new HttpGet(
                    URL.toString() );




            try {
                HttpResponse response = client.execute(httpGet);
                StatusLine statusLine = response.getStatusLine();
                int statusCode = statusLine.getStatusCode();
                if (statusCode == 200) {
                    HttpEntity entity = response.getEntity();
                    InputStream content = entity.getContent();
                    BufferedReader reader = new BufferedReader(
                            new InputStreamReader(content));


                    // Read the JSON 
                    Result = reader.readLine();

                    // Convert the string to Array


                    GlobalVariables appState = new GlobalVariables();

                    appState.encounters =new ArrayList<Encounter>(); 



                    JSONArray array=new JSONArray(Result);

                    // Loop through and fill 
                    for(int i=0;i<array.length();i++){

                        JSONObject elem=(JSONObject)array.get(i);
                        Encounter encounter=new Encounter();

                        encounter.PatientID=elem.getInt("PatientID");
                        encounter.PatientName = elem.getString("PatientName");

                        encounter.NOKName= elem.getString("NOKName");
                        encounter.ReferalName= elem.getString("ReferalName");

                        encounter.bookingDate= elem.getString("bookingDate");
                        encounter.Onclogist= elem.getString("Onclogist");
                        encounter.EncounterStatus= elem.getString("EncounterStatus");

                        encounter.EncounterType= elem.getString("EncounterType");
                        encounter.Regieme= elem.getString("Regieme");


                        appState.encounters.add(encounter);
                    }




                } else {
                     Result = "error";
                }
            } catch (ClientProtocolException e) {
                 Result = "error";
                e.printStackTrace();
            } catch (IOException e) {
                 Result = "error";
                e.printStackTrace();
            }







    } catch (Exception e) {
      e.printStackTrace();
    }

          return null;
      }        
    @Override
      protected void onPostExecute(Void result) {
        connectionProgressDialog.dismiss();
      }
  }


---------------- and I call it in --------------

/*
 * This class to provide the code for the Chemo unit screen that will be used
 * 
 * */

package com.appnetics;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class ChemoUnit  extends Fragment {

    /*The main controls*/
    TextView Patient, Nok ,  Referrer , Oncologist = null ;
    ListView MainGrid ;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {


         View view = inflater.inflate(
                    R.layout.chemounit,
                    container,
                    false);
        // Intialize the Controls
         Patient = ((TextView) view.findViewById(R.id.Patient));
         Nok = ((TextView) view.findViewById(R.id.Nok));
         Referrer = ((TextView) view.findViewById(R.id.Referrer));
         Oncologist = ((TextView) view.findViewById(R.id.Oncologist));




        //Intialize the record Grid
         LinearLayout formLayout = (LinearLayout)view.findViewById(R.id.ChemoUnitGrid);
        formLayout.removeAllViews();

        MainGrid = new ListView(getActivity().getApplicationContext());              
        MainGrid.setVisibility(ListView.VISIBLE);
         LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                 LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
         params.gravity = Gravity.RIGHT;
         MainGrid.setLayoutParams(params);



         //1. set the header 

         ViewGroup header = (ViewGroup)inflater.inflate(R.layout.chemounitgridheader, MainGrid, false);
         MainGrid.addHeaderView(header, null, false);

         //2. Call the web Service 


         new EncounterBackgroundWorker( getActivity() ).execute();

         MainGrid.setAdapter(new Encounteradapter(view.getContext(), null));
        // Finally add it 

         formLayout.addView(MainGrid);



         // Return the Result 
        return inflater.inflate(R.layout.chemounit, container, false);
    }
  • 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-06-05T10:59:55+00:00Added an answer on June 5, 2026 at 10:59 am

    Use:

    getActivity().getApplication();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many questions about this PersistenceException, but I have not seen some, where
Thanks in advance for your help. I have a need within an application to
There are many conflicting statements around. What is the best way to get the
There is this strange situation I'm fighting on. I have 3 pages, les call
There have been multiple questions regarding this topic but I have never really settled
There is an application written in PHP which I am converting to Ruby. When
There are a few ways to get class-like behavior in javascript, the most common
There are numerous Agile software development methods. Which ones have you used in practice
There's a common error that gets thrown by the Visual C Runtime: This application
There is a website with an AJAX API. I have opened Firebug to look

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.