Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen Activity with surfaceView add to TabActivity,The window will flicker with a whole screen black when the tab is activated for the first time
    primarykey
    data
    text
    <p>I have a TabActivity which have two tabs.Each tab associates with an Intent。 And the second tab have a surfaceview in layout,To oppose the problem,I just put an SurfaceView Tag of 100dip width and 100dip height and do nothing。When the TabActivity have loaded,I press the second tab。 Then the whole screen have a flicker of black for a second。</p> <p>And further more,I wrote some code to let the surface do a canvas.drawColor(Color.red);the flicker of black still happened.</p> <p>Could someone help?</p> <p>Here is my code.</p> <h1>TabActivity</h1> <pre><code>public class TestFlickerAcivity extends TabActivity { private TabHost tabHost; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test_flicker_acivity); tabHost = getTabHost(); createTabs(); } private void createTabs() { Intent tab1Intent = new Intent(this, Tab1Activity.class); tab1Intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); TabSpec tab1 = tabHost.newTabSpec("TAB1").setIndicator("tab1").setContent(tab1Intent); tabHost.addTab(tab1); Intent tab2Intent = new Intent(this, Tab2Activity.class); tab2Intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); TabSpec tab2 = tabHost.newTabSpec("TAB2").setIndicator("tab2").setContent(tab2Intent); tabHost.addTab(tab2); } } </code></pre> <h1>Tab2 Layout</h1> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;SurfaceView android:layout_width="100dip" android:layout_height="100dip" android:id="@+id/tab2Surface" /&gt; &lt;/RelativeLayout&gt; </code></pre> <h1>Tab2 activity:</h1> <pre><code>public class Tab2Activity extends Activity implements Callback, Runnable { private boolean mIsRunning; private SurfaceHolder mHolder; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tab2); SurfaceView sv = (SurfaceView) findViewById(R.id.tab2Surface); sv.getHolder().addCallback(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_tab2, menu); return true; } @Override public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) { } @Override public void surfaceCreated(SurfaceHolder holder) { mHolder = holder; Canvas canvas = mHolder.lockCanvas(); canvas.drawColor(Color.RED); mHolder.unlockCanvasAndPost(canvas); Thread t = new Thread(this); mIsRunning = true; t.start(); } @Override public void surfaceDestroyed(SurfaceHolder arg0) { mIsRunning = false; } @Override public void run() { while (mIsRunning) { Canvas canvas = mHolder.lockCanvas(); canvas.drawColor(Color.RED); mHolder.unlockCanvasAndPost(canvas); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload