-1

I am parsing a XML file that is stored in my device SD card.It is taking approx above to start the activity .

this is what i am getting in my LOG

09-23 17:30:15.083: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 57ms
09-23 17:30:15.938: D/dalvikvm(27040): GC_CONCURRENT freed 1498K, 11% free 15192K/16887K, paused 12ms+13ms, total 122ms
09-23 17:30:15.939: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 98ms
09-23 17:30:16.772: D/dalvikvm(27040): GC_CONCURRENT freed 1939K, 13% free 15195K/17335K, paused 12ms+23ms, total 256ms
09-23 17:30:16.774: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 235ms
09-23 17:30:17.252: D/dalvikvm(27040): GC_CONCURRENT freed 1910K, 13% free 15204K/17335K, paused 1ms+3ms, total 161ms
09-23 17:30:17.253: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 98ms
09-23 17:30:17.955: D/dalvikvm(27040): GC_CONCURRENT freed 1912K, 13% free 15212K/17335K, paused 14ms+12ms, total 139ms
09-23 17:30:17.955: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 93ms
09-23 17:30:18.720: D/dalvikvm(27040): GC_CONCURRENT freed 1914K, 13% free 15217K/17335K, paused 13ms+3ms, total 153ms
09-23 17:30:18.722: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 86ms
09-23 17:30:19.349: D/dalvikvm(27040): GC_CONCURRENT freed 1912K, 13% free 15224K/17335K, paused 2ms+2ms, total 140ms
09-23 17:30:19.351: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 85ms
09-23 17:30:20.094: D/dalvikvm(27040): GC_CONCURRENT freed 1906K, 13% free 15232K/17335K, paused 2ms+13ms, total 169ms
09-23 17:30:20.096: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 157ms
09-23 17:30:21.848: D/dalvikvm(27040): GC_CONCURRENT freed 1899K, 13% free 15237K/17335K, paused 14ms+21ms, total 443ms
09-23 17:30:21.849: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 310ms
09-23 17:30:22.233: D/dalvikvm(27040): GC_CONCURRENT freed 1957K, 13% free 15245K/17399K, paused 5ms+2ms, total 96ms
09-23 17:30:22.234: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 70ms
09-23 17:30:22.589: D/dalvikvm(27040): GC_CONCURRENT freed 1912K, 13% free 15252K/17399K, paused 1ms+3ms, total 68ms
09-23 17:30:22.590: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 53ms
09-23 17:30:23.267: D/dalvikvm(27040): GC_CONCURRENT freed 1914K, 13% free 15258K/17399K, paused 3ms+198ms, total 454ms
09-23 17:30:23.268: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 435ms
09-23 17:30:23.639: D/dalvikvm(27040): GC_CONCURRENT freed 1912K, 13% free 15265K/17399K, paused 14ms+2ms, total 88ms
09-23 17:30:23.641: D/dalvikvm(27040): WAIT_FOR_CONCURRENT_GC blocked 49ms

Code Activity

resultTrips = (LinearLayout) findViewById(R.id.trip_list);
LinearLayout.LayoutParams mainTripDetailsLayout = new LinearLayout.LayoutParams(
        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
LayoutInflater inflater = (LayoutInflater) getBaseContext()
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout.LayoutParams forUnderLine = new LinearLayout.LayoutParams(
        LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
forUnderLine.setMargins(0, 0, 0, 0);
mainTripDetailsLayout.setMargins(0, 40, 0, 0);
File fXmlFile = new File("/storage/sdcard1/Android/myXML.xml");
if(fXmlFile.exists()){
    obj = new ParseMyXML();
    MyTripRespone data = obj.parseMyTripXML(fXmlFile);
    List<Approvals> listdata = data.getCoroprateBookingDetails();
    int i=0;
    for (Approvals elements : listdata) {

        TextView line = new TextView(this);
        line.setBackgroundResource(R.layout.shape_line);
        line.setLayoutParams(forUnderLine);
        if (i != 0) {
            resultTrips.addView(line);
        }

        final LinearLayout tripdetailsdata = (LinearLayout) inflater.inflate(
                R.layout.tripdetailsdata, null);
        try {
            tripDate = input.parse(elements.getJourneyDate());
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        tripdetailsdata.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
            Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)", Toast.LENGTH_LONG).show();    
            }
        });
        i++;
    }
}
TextView dummy = new TextView(this);
dummy.setLayoutParams(mainTripDetailsLayout);
resultTrips.addView(dummy);

Please suggest me what changes i have to make so that my app becomes fast .It is very slow .Please suggest me i am new in android

Developer
  • 6,292
  • 19
  • 55
  • 115
Pooja Dubey
  • 683
  • 2
  • 14
  • 34
  • 1
    do parsing process in AsyncTask – Biraj Zalavadia Sep 23 '13 at 12:18
  • yes, it will be great if you used the Asynctask and SAX parser. Below is the link http://www.jondev.net/articles/Android_XML_SAX_Parser_Example – Amit Sep 23 '13 at 12:19
  • @BirajZalavadia which part i have to put in asynk and how please let me know i am new in android – Pooja Dubey Sep 23 '13 at 12:20
  • And also you should use Listview instead LinearLayout. – Biraj Zalavadia Sep 23 '13 at 12:27
  • @BirajZalavadia please help me how could i do this in AsyncTask – Pooja Dubey Sep 23 '13 at 12:32
  • @PoojaDubey get to know asynctask first from the docs http://developer.android.com/reference/android/os/AsyncTask.html. If you don't know how to implement asynctask after reading docs come back and post what you have tried with asynctask – Raghunandan Sep 23 '13 at 12:33
  • @Raghunandan i have already done this asynctask for Login part in app .but i am confused how i will return the data from doInBackground i am doing this on create MyTripRespone data = obj.parseMyTripXML(fXmlFile); so in need to return the data – Pooja Dubey Sep 23 '13 at 12:36
  • @Raghunandan so please if u can help me with a sample i will be thank full to u – Pooja Dubey Sep 23 '13 at 12:37
  • @PoojaDubey it depends on whether your asynctask is an inner class of the activity class or is it a separate if so you can use interface as call back. http://stackoverflow.com/questions/18723282/cant-post-response-from-asynctask-to-mainactivity/18723363#18723363 – Raghunandan Sep 23 '13 at 12:37
  • @Raghunandan the class in not inner it is a sepreate class – Pooja Dubey Sep 23 '13 at 12:39
  • check the link in my previous comment. use a interface – Raghunandan Sep 23 '13 at 12:40

2 Answers2

1

In my opinion mainn thing is not implement parser in GUI thread. Most simple way is use extension of AsyncTask to prase XML and show results in GUI thread.

TommyNecessary
  • 1,377
  • 1
  • 13
  • 19
0

Updated Answer Try this

public class ParseXMLTask extends AsyncTask<String, Void, MyTripRespone> {
    ParseMyTripResponseXML obj;
    Context context;
    CallBack callBack;

    public ParseXMLTask(CallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }

    @Override
    protected MyTripRespone doInBackground(String... arg0) {
        obj = new ParseMyTripResponseXML();
        MyTripRespone data = obj.parseMyTripXML(SelfApprovals.fXmlFile);
        return data;
    }
    protected void onPostExecute(MyTripRespone result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        callBack.run(result);

    }
}
Developer
  • 6,292
  • 19
  • 55
  • 115