开发者

Starting Activity via Intent is slow / shows considerable delay - why?

I have a very simple MainActivity, and from that Activity I start the other Activity (with theme Dialog so it floats on top of the MainActivity.

The problem is that there is always a delay before the second Activity show up. I'd say it takes almost 1 second for it to show, and there is no code at all in second Activity. The only code in the second Activity is this:

package MyPackage;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class JobViewActivity extends Activity {

    @Override
    protected void onCreate(android.os.Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.jobview);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}

The MainActivity has a ListView with Nodes, and there is a click listener connected to the ListView in the onCreate like this:

public void onCreate(Bundle savedInstanceState) 
{
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    _nodeRowAdapter = new NodeRowAdapter(this, _nodes);

    listView = (ListView)findViewById(R.id.ListViewNodes);
    listView.setAdapter(_nodeRowAdapter);   

    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(getApplicationContext(), JobViewActivity.class);
            startActivity(i);
        }
    });

But when the ListItem is pressed, and the Click listener is triggered, it takes about 1 second to show the "popup".

The layout isn't very advanced in the popup. Here is the layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:weightSum="1" 
  android:stretchColumns="1" android:orientation="vertical">

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:stretchColumns="1" android:layout_height="wrap_content" android:id="@+id/tableLayout1">
        <TableRow>
            <TextView
                android:text="Id: "
                android:padding="10dip"/>
            <TextView
                android:text="Ext id: "
                android:gravity="right"
                android:padding="10dip" />
        </TableRow>
     </TableLayout>


    <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="@+id/relativeLayout1">
        <LinearLayout android:id="@+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#E7F3F1">
             <Button android:text="Start" android:id="@+id/button1" style="@style/ButtonText" android:layout_weight="1" android:background="@drawable/button_green"></Button>

            <Button android:text="Bom" android:id="@+id/button2" style="@style/ButtonText" android:layout_weight="1" android:background="@drawable/button_red"></Button>
            <Button android:text="Mer" android:id="@+id/button3" style="@style/ButtonText" android:layout_weight="1" android:background="@drawable/button_yellow"></Button>
            <Button android:text="Nav" android:id="@+id/button4" style="@style/ButtonText" android:layout_weight="1"></Button>
        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="@+id/tableLayout1" android:layout_alignParentLeft="true" android:layout_above="@+id/relativeLayout1" android:padding="6dip">
        <TextView style="@style/JobViewHeader" android:id="@+id/textView1" android:text="Something: "></TextView>
        <TextView style="@style/JobViewHeader" android:id="@+id/TextView2" android:text="Something: " android:layout_below="@+id/textView1"></TextView>
        <TextView style="@style/JobViewHeader" android:id="@+id/TextView3" android:layout_marginTop="16dp" android:text="Kund: " android:layout_below="@+id/TextView2"></TextView>
        <TextView style="@style/JobViewHeader" android:id="@+id/TextView4" android:text="Something: " android:layout_below="@+id/TextView3"></TextView>
        <TextView style="@style/JobViewHeader" android:id="@+id/TextView5" android:text="Something: " android:layout_below="@+id/TextView4"></TextView>
        <TextView style="@style/JobViewHeader" android:id="@+id/TextView6" android:text="Something: " android:layout_below="@+id/TextView5"></TextView>
        <TextView style="@style/JobViewHeader" android:id="@+id/TextView7" android:text="Something: " android:layout_below="@+id/TextView6"></TextView>
        <TextView style="@style/JobViewHeader" android:id="@+id/TextView8" android:layout_marginTop="20dp" android:text="Something: " android:layout_below="@+id/TextView7"></TextView>

        <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/textView1" android:layout_alignBottom="@+id/textView1" android:layout_toRightOf="@+id/textView1" android:id="@+id/textViewPickuptime"></TextView>
        <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/TextView2" android:layout_alignBottom="@+id/TextView2" android:layout_toRightOf="@+id/TextView2" android:id="@+id/textViewPickupAddress"></TextView>
        <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="@+id/TextView4" android:layout_toRightOf="@+id/TextView3" android:id="@+id/textViewCustomer"></TextView>
        <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/TextView4" android:layout_alignBottom="@+id/TextView4" android:layout_toRightOf="@+id/TextView4" android:id="@+id/textViewNbrOfPassengers"></TextView>
       开发者_开发技巧 <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="@+id/TextView6" android:layout_toRightOf="@+id/TextView5" android:id="@+id/textViewRoutine"></TextView>
        <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/TextView6" android:layout_alignBottom="@+id/TextView6" android:layout_toRightOf="@+id/TextView6" android:id="@+id/textViewServiceFee"></TextView>
        <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="@+id/TextView7" android:layout_alignBottom="@+id/TextView7" android:layout_toRightOf="@+id/TextView7" android:id="@+id/textViewHelp"></TextView>
        <TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_below="@+id/TextView8" android:layout_alignLeft="@+id/TextView8" android:id="@+id/textViewExtra"></TextView>
    </RelativeLayout>
</RelativeLayout>

Im not sure what else to tell you, there isnt much more too it.

Im testing on a device, Samsung Galaxy S2.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜