Android 通过Intent启动活动缓慢/显示出相当大的延迟-为什么?

Android 通过Intent启动活动缓慢/显示出相当大的延迟-为什么?,android,Android,我有一个非常简单的MainActivity,然后从该活动开始另一个活动(使用主题对话框),使其浮动在MainActivity之上 问题是,在第二个活动出现之前总是有一个延迟。我想说,它几乎需要1秒的时间才能显示出来,第二个活动中根本没有代码。第二个活动中唯一的代码是: package MyPackage; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; impo

我有一个非常简单的MainActivity,然后从该活动开始另一个活动(使用主题对话框),使其浮动在MainActivity之上

问题是,在第二个活动出现之前总是有一个延迟。我想说,它几乎需要1秒的时间才能显示出来,第二个活动中根本没有代码。第二个活动中唯一的代码是:

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();
    }
}
MainActivity有一个带有节点的ListView,在onCreate中有一个连接到ListView的单击侦听器,如下所示:

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);
        }
    });
public void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(窗口。功能\u无\u标题);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_nodeRowAdapter=新的nodeRowAdapter(这,\u个节点);
listView=(listView)findViewById(R.id.ListViewNodes);
setAdapter(_nodeRowAdapter);
setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
意图i=新意图(getApplicationContext(),JobViewActivity.class);
星触觉(i);
}
});
但是,当按下ListItem并触发Click listener时,大约需要1秒来显示“弹出窗口”

弹出窗口中的布局不是很高级。以下是布局:

<?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>

我不知道还能告诉你什么,没有太多了


我在三星Galaxy S2设备上进行测试。

如果JobView在子布局和嵌套深度方面非常大,那么膨胀时间可能会有点长。但我不知道这是否是问题所在。我会添加一些日志记录,并确定延迟在何处。这可能发生在调用
onItemClick
之前或调用之后e> startActivity。了解这一点可以帮助我们理解问题。@MrJre:我可以完全清空XML(如上所述),所以它几乎不包含任何内容。它仍然明显滞后。@MrJre:好的,如果我完全删除所有XML,它实际上会更快。我用XML进行了更新…我相信有几个对齐的RelativeLayout可能会有点慢