【问题标题】:Calling WebService on OnCreate() causes performance Issue in android在 OnCreate() 上调用 WebService 会导致 android 出现性能问题
【发布时间】:2012-02-28 12:21:33
【问题描述】:

在我的应用程序中,我使用 TabGroupActivity 在单个选项卡下拥有多个孩子。我曾经在活动的onCreate方法中调用Web服务,每当我导航到child并单击返回按钮时,onCreate方法将再次调用(第二次),它似乎性能较低。

前:` @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        getBundle = new Bundle();
        getBundle=getIntent().getExtras();           
        intentData = getBundle.getString("Search_Result");
        bikeItemList=new ArrayList<SearchResultsIdentifier>();
        System.out.println("sdf"+bikeItemList.size());
        DataService searchDS = new DataService();
        try {
            URL test=new URL(intentData);
            itemList=searchDS.getSearchList(test);
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        final ListView lv1 = (ListView) findViewById(R.id.list);
        lv1.setAdapter(new ListAdapter(tList.this,R.layout.search_bike,itemList,this));




    }`

如何避免这种情况,根据 android 活动图,当我导航到子项时单击 bak onCreate 不会调用,但在这里我使用选项卡组活动。如何解决两次 Web 服务调用问题。

【问题讨论】:

    标签: android android-intent


    【解决方案1】:

    【讨论】:

    • 实际上我使用线程来访问服务....但它调用了两次这是我的问题
    • 不,有问题。你可以这样称呼itemList=searchDS.getSearchList(test)。在这个地方程序正在等待getSearchList() 返回!
    • 是的,我只在 AsyncTask 中执行此操作,但我的问题是当我启动此活动时它工作正常,然后我单击列表导航到下一个活动,当我再次从子项单击返回时 onCreate方法被调用。
    • 提供的两个链接都已损坏
    猜你喜欢
    • 1970-01-01
    • 2017-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 2015-02-16
    相关资源
    最近更新 更多