应用显示黑屏? [英] Application showing black screen?

查看:113
本文介绍了应用显示黑屏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是执行一个Android应用程序。我使用一个活动Web服务。我显示一个进度对话框,直到它加载第二个活动。但它并没有显示整个时间,并显示黑屏了time.It看起来像应用程序挂起。我该怎么办?我浪费了我的三个日子。我使用的AsyncTask这些过程。请帮我。

 保护无效onListItemClick(ListView中升,视图V,最终诠释的位置,
        长ID){
    super.onListItemClick(L,V,位置ID);    progressDialog = ProgressDialog.show(ProjectListActivity.this,
            请稍候...,载入中...);    新的Thread(){        公共无效的run(){            尝试{
                字符串项目= titles.get(位置 - 1);                performBackgroundProcess(项目);            }赶上(例外五){                Log.e(标签,e.getMessage());            }            progressDialog.dismiss();
        }    }。开始();}   私人无效performBackgroundProcess(字符串项目){    字符串spaceId = NULL;
    字符串SPACENAME = NULL;
    / *
     *为(太空空间:空格){
     *如果(space.getName()。equalsIgnoreCase((字符串)((的TextView)
     * v)的.getText())){spaceId = space.getId(); }}
     * /
    对于(太空空间:空格){        如果(project.equals(space.getName())){            时讯=空间;
        }    }    spaceId = newSpace.getId();
    SPACENAME = newSpace.getName();    / *
     *意向意图=新意图(这一点,SpaceComponentsActivity.class);
     * intent.putExtra(spaceId,spaceId); intent.putExtra(tabId,0);
     * intent.putExtra(类名,TicketListActivity); TabSettings TS =
     *新TabSettings(); ts.setSelTab(1); this.startActivity(意向);
     * /
    意向意图=新意图(这一点,SpaceComponentsActivity.class);
    intent.putExtra(spaceId,spaceId);
    intent.putExtra(tabId,0);
    intent.putExtra(SPACENAME,SPACENAME);    // intent.putExtra(类名,TicketListActivity);
    TabSettings TS =新TabSettings();
    ts.setSelTab(0);
    ts.setSelTabClass(Ti​​cketListActivity);
    this.startActivity(意向);    / *
     * Toast.makeText(getApplicationContext(),((TextView的)V).getText()
     * Toast.LENGTH_SHORT).show();
     * /
}


解决方案

有关你的情况使用本...

progressDialog 公众对你的活动

  progressDialog = ProgressDialog.show(ProjectListActivity.this,
        请稍候...,载入中...);新的Thread(){    公共无效的run(){        尝试{
            字符串项目= titles.get(位置 - 1);            performBackgroundProcess(项目);
            ProjectListActivity.this.runOnUiThread(新的Runnable(){        @覆盖
        公共无效的run(){
            progressDialog.dismiss();        }
    });        }赶上(例外五){            Log.e(标签,e.getMessage());        }
    }}。开始();

但它不是一个很好的计算策略使用 AsyncTask的

I am implementation an android application. I am using web service on one activity. I am showing a progress dialog until it loads second Activity. But it does not show for whole time and shows black screen for a time.It looks like application hang. What should i do? i wasted my three day. I am using asynctask for these process. Please help me .

protected void onListItemClick(ListView l, View v, final int position,
        long id) {
    super.onListItemClick(l, v, position, id);

    progressDialog = ProgressDialog.show(ProjectListActivity.this,
            "Please wait...", "Loading...");

    new Thread() {

        public void run() {

            try {
                String project = titles.get(position - 1);

                performBackgroundProcess(project);

            } catch (Exception e) {

                Log.e("tag", e.getMessage());

            }

            progressDialog.dismiss();
        }

    }.start();

}



   private void performBackgroundProcess(String project) {

    String spaceId = null;
    String spaceName = null;
    /*
     * for (Space space : spaces){
     * if(space.getName().equalsIgnoreCase((String) ((TextView)
     * v).getText())){ spaceId = space.getId(); } }
     */
    for (Space space : spaces) {

        if (project.equals(space.getName())) {

            newSpace = space;
        }

    }

    spaceId = newSpace.getId();
    spaceName = newSpace.getName();

    /*
     * Intent intent = new Intent(this, SpaceComponentsActivity.class);
     * intent.putExtra("spaceId", spaceId); intent.putExtra("tabId", 0);
     * intent.putExtra("className", "TicketListActivity"); TabSettings ts =
     * new TabSettings(); ts.setSelTab(1); this.startActivity(intent);
     */
    Intent intent = new Intent(this, SpaceComponentsActivity.class);
    intent.putExtra("spaceId", spaceId);
    intent.putExtra("tabId", 0);
    intent.putExtra("spaceName", spaceName);

    // intent.putExtra("className", "TicketListActivity");
    TabSettings ts = new TabSettings();
    ts.setSelTab(0);
    ts.setSelTabClass("TicketListActivity");
    this.startActivity(intent);

    /*
     * Toast.makeText(getApplicationContext(), ((TextView) v).getText(),
     * Toast.LENGTH_SHORT).show();
     */
}

解决方案

for your case use this...

made progressDialog public to your Activity

progressDialog = ProgressDialog.show(ProjectListActivity.this,
        "Please wait...", "Loading...");

new Thread() {

    public void run() {

        try {
            String project = titles.get(position - 1);

            performBackgroundProcess(project);
            ProjectListActivity.this.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            progressDialog.dismiss();

        }
    });

        } catch (Exception e) {

            Log.e("tag", e.getMessage());

        }


    }

}.start();

but it is not a good approch use AsyncTask.

这篇关于应用显示黑屏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆