4

我正在使用我的一项活动中的以下代码来开始另一项活动

Intent viewIntent = new Intent(getApplicationContext (), landingPage.class);
Bundle b = new Bundle();
b.putString("ApplicationName", a_Bean.getApplicationName());
if (landingPage.getInstanceCount() < 1)
    bp.landingPage_ProgressDialog = ProgressDialog.show(ViewAllApp.this, "Please wait...", "Retrieving data...", true, false);
viewIntent.putExtras(b);
viewIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivityForResult(viewIntent,10);
Thread background = new Thread(new Runnable() {
    public void run() {
        Progresshandler.sendMessage(handler.obtainMessage());//finishes progressDialog
}});
background.start();

但是在 startactivity 之后它显示一个黑屏然后显示新的活动。我可以在显示黑屏时显示进度对话框吗?

4

3 回答 3

5

这对我有用:

Intent intent = new Intent(LocationGrid.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
overridePendingTransition(0, 0);
于 2015-05-05T05:22:35.967 回答
1

您的代码有点混乱和不清楚。请指定目标。无论如何,我看到的一些事情:

1- 不要使用 getApplicationContext(),Activity 本身就是一个 Context,因此最好使用:

new Intent (this, landingPage.class);

2-您无需创建 Bundle 即可将字符串添加到意图。

viewIntent.addExtra("ApplicationName", a_Bean.getApplicationName ());

无论如何,在你的活动中传递应用程序的名称对我来说似乎是一个可怕的想法。如果您在整个活动中确实需要应用程序的名称,请创建一个 Application 类作为应用程序的中心点。我真的建议你重新审视你的架构。

3- 你确定要从它的父亲那里访问活动的landingPage 吗?我假设landingPage 在某处被实例化。我觉得这是一个糟糕的方法。如果我错了,请举例说明。

至于其余的代码和你的确切问题,我无法回答,我没有使用过进度对话框,但我们甚至不知道“bp”变量是什么,正如我所说,你应该尝试再次询问您的问题以澄清一些观点。

于 2010-09-13T09:24:03.307 回答
1

我通过将DataLoader(即从Internet 加载数据的方法)从被调用类(即我的landingPage.class)中删除到调用者类来解决了上述问题。

于 2010-09-22T09:17:34.313 回答