活动之间切换黑屏

发布于 2024-09-18 16:30:18 字数 747 浏览 8 评论 0原文

我正在使用我的一个活动中的以下代码来启动另一个活动

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();

,但在启动活动后它显示黑屏&然后显示新活动。 我可以让进度对话框在显示黑屏时显示吗?

I am using below code from one of my activity to start another

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();

but after startactivity it shows a black screen & then displays new activity.
Can I make progressdialog to be shown while the black screen is displayed??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

执妄 2024-09-25 16:30:18

这对我有用:

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);

This worked for me:

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);
天煞孤星 2024-09-25 16:30:18

你的代码有点混乱和不清楚。请具体说明目标。无论如何,我看到了一些事情:

1-不要使用 getApplicationContext(),活动本身就是一个上下文,因此最好使用:

new Intent (this, landingPage.class);

2-您不需要创建一个 Bundle 来将字符串添加到意图中。

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

不管怎样,在你的活动中传递应用程序的名称对我来说似乎是一个可怕的主意。如果您确实需要在整个活动中使用应用程序的名称,请创建一个应用程序类作为应用程序的中心点。我真的建议你重新审视你的架构。

3- 您确定要从其父活动landingPage 访问活动吗?我假设landingPage 是在某处实例化的。我发现这是一个糟糕的方法。如果我错了,请提供例子。

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

Your code is a bit confusing and unclear. Please specify the goal. Anyway, some things I see:

1- Do not use getApplicationContext(), an Activity is a Context itself, thus it's better to use:

new Intent (this, landingPage.class);

2- You don't need to create a Bundle to add a string to to an intent.

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

Anyway, passing around your activities the application's name seems like a horrible idea to me. If you really need the application's name throughout the activities, create an Application class as the central point of your application. I really recommend you to revisit your architecture.

3- Are you sure you want to access the activity landingPage from its father? I assume that landingPage is instantiated somewhere. I find this to be a terrible approach. If I am wrong, please provide examples.

As for the rest of the code and your precise question, I can't answer it, I haven't worked with Progress dialogs, but we don't even know what the "bp" variable is and, as I said, you should try to ask again your question clarifying some points.

赢得她心 2024-09-25 16:30:18

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

I resolved above issue by removing DataLoader(i.e. methods that load data from Internet) from called class(i.e. my landingPage.class) to the caller class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文