在android上如何在切换活动(不工作)时移除黑屏

在android上如何在切换活动(不工作)时移除黑屏,android,android-asynctask,android-activity,Android,Android Asynctask,Android Activity,在我的应用程序中,我将一个活动切换到另一个活动(Main.java到Feature_Screen.java)。在Feature_屏幕(第二个活动)中,我将下载大量数据和图像,以在网格视图中进行设置。所以我使用异步任务来下载它。虽然我在第二个活动中使用了异步任务,但当我将Main.java切换到Feature.java时,会出现黑屏。我在谷歌搜索,但所有的答案都说使用异步任务 示例编码: public class Main extends TabActivity{ public void onC

在我的应用程序中,我将一个活动切换到另一个活动(Main.java到Feature_Screen.java)。在Feature_屏幕(第二个活动)中,我将下载大量数据和图像,以在网格视图中进行设置。所以我使用异步任务来下载它。虽然我在第二个活动中使用了异步任务,但当我将Main.java切换到Feature.java时,会出现黑屏。我在谷歌搜索,但所有的答案都说使用异步任务

示例编码:

public class Main extends TabActivity{

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabbar);
    .................
    intent = new Intent().setClass(this, Featured_Screen1.class);
    spec = tabHost.newTabSpec("home").setIndicator("",
            res.getDrawable(R.drawable.top_book_icon)).setContent(intent);
    tabHost.addTab(spec);
    ...........
}
}
在Feature_Screen1.java(Second.java)中:

公共类功能\u屏幕1扩展活动{
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.feature);
.................
新内容加载().execute();
...........
}
类内容\u加载扩展异步任务
{
ProgressDialog=新建ProgressDialog(SignInPage.this);
受保护的void onPreExecute(){
setMessage(“请稍候…”);
对话框。可设置可取消(false);
dialog.show();
}
受保护的void onPostExecute(未使用的void){
dialog.dismise();
}
受保护的Void doInBackground(Void…arg0){
..........
返回null;
}
} 
}

我的问题是如何避免在活动之间切换时出现黑屏?请帮帮我。

我终于找到了黑屏问题的答案

使用下面的异步任务,这对我来说很有效,如果你遇到任何问题,请告诉我

public class SyncroniseRecords extends AsyncTask<Void, Void, Void>
{  
    @Override
    protected void onPreExecute()
    {  
        super.onPreExecute();
        dialog.setMessage("Please wait...");
        dialog.setCancelable(false);
        dialog.show();

    } 
    @Override 
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
        // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
     }

    @Override 
    protected void onPostExecute(Void result)
    { 
           dialog.cancel();
    }
    @Override
    protected Void doInBackground(Void... params) {

        return null;
    }
} 
公共类SyncroniseRecords扩展异步任务
{  
@凌驾
受保护的void onPreExecute()
{  
super.onPreExecute();
setMessage(“请稍候…”);
对话框。可设置可取消(false);
dialog.show();
} 
@凌驾
受保护的void onProgressUpdate(void…值){
super.onProgressUpdate(值);
//正在执行长时间运行的操作时要执行的操作。例如更新ProgessDialog
}
@凌驾
受保护的void onPostExecute(void结果)
{ 
dialog.cancel();
}
@凌驾
受保护的Void doInBackground(Void…参数){
返回null;
}
} 

这将在没有任何黑屏的情况下启动活动。使用
onPreExecute
可以显示进度条。一旦流程完成,您可以在
OnPostExecute()

中取消它,您是否看到“请等待”对话框?是的,但在获得“请等待”之前几秒钟后我就出现了黑屏,请稍候……这看起来像是异步任务开始前挂在UI线程上的东西。在新内容加载()之前发布dots代码。执行();在您的功能屏幕中,1.onCreate()可能会帮助其他人发现您的问题。@murali\u ma hi buddy。。你的问题有答案吗。。因为我现在面临同样的问题。。。如果你有答案,请把它贴出来。。这真的很有帮助。。thanks@user1216003嗨,伙计,不,我没有得到这个问题的答案。我猜UI也挂在活动中。非常感谢你的友好回复。我在android中有一个问题,那就是我需要将wav文件转换成mp3。你知道怎么做吗?请帮帮我。我想永远和你联系。你解决了那个问题吗。请把wav转换成mp3。它可能会帮助你。。
public class SyncroniseRecords extends AsyncTask<Void, Void, Void>
{  
    @Override
    protected void onPreExecute()
    {  
        super.onPreExecute();
        dialog.setMessage("Please wait...");
        dialog.setCancelable(false);
        dialog.show();

    } 
    @Override 
    protected void onProgressUpdate(Void... values) {
        super.onProgressUpdate(values);
        // Things to be done while execution of long running operation is in progress. For example updating ProgessDialog
     }

    @Override 
    protected void onPostExecute(Void result)
    { 
           dialog.cancel();
    }
    @Override
    protected Void doInBackground(Void... params) {

        return null;
    }
}