简体   繁体   中英

getting Black Screen while while changing Activity

I am facing the problem of black screen while changing the activity from one to another. I found the answer why this is happening but could not find the solution for it. When I go from my playActivity to GameCompleteActivity from where I can go to next level while going to next level I am finishing the instance of playActivity and calling new Intent for the same PlayActivity because my all different level works in the PlayActivity , becoz of my requirement I have to finish the last playActivity to start new playActivity for the next Level . This is where I get lag or black screen while going to the next level ie after finish and again starting the playActivity it takes time.

I tried Transculent.Theme also but it did not work. AsyncTask also did not gave me the desired result

Now i thought I show some animation of activity fading or something that might hide my black screen behaviour ?

need help in solution ? ....thanks

This usually means that the new activity is loading data in the UI thread, hence the screen stays black until everything is loaded up.

Consider moving the code that loads all the Activitys data (it's a game so I guess the level & graphics) in a separate thread and then lets the PlayActivity know when the data is ready to use.

如果您的onCreate中有大量的UI相关代码,只需尝试通过创建一些函数IntializeUI()在onCreate之外进行,或者尝试将其划分为模块化,或者使用Transculent主题进行活动...

这是一个非常简单的错误:只需在您的清单文件属性中添加到您的活动:android:theme =“@ android:style / ... - 并将其变为半透明。

While it's possible that too much activity on the main thread will do this, in my experience the most common / noticeable cause is calling finish() immediately after startActivity() when transitioning. Not saying it's wrong to do this, but if you want to get rid of the black screen you may need to try another approach such as using noHistory .

Whenever Such kind of thing Happens Remember to Debug when new Activity is called.

While making any Game, try to make partitions of different different Modules. So gets Easy to Trace your Problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM