Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating UI Activity in Thread
    primarykey
    data
    text
    <p>here is my problem. I am programming an android app, which needs to display the time the activity it is running. Therefor I created a new Thread which is called from the activity. However when I start the app in the emulator, it seems the Activity is never loaded. Maybe you guys can help me here. Here is the relevant code:</p> <pre><code>public class ActivityStartTracker extends ActivityBasic { TimerThread timer; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start); timer = new TimerThread(); } protected void onResume() { super.onResume(); registerReceiver(broadcastReceiver, new IntentFilter( ServiceLocator.BROADCAST_ACTION)); timer.run(); } protected void onPause() { super.onPause(); unregisterReceiver(broadcastReceiver); if (timer.isRunning()) { timer.interrupt(); } } class TimerThread extends Thread { boolean isRunning = false; public TimerThread() { } @Override public void run() { int seconds = 0; isRunning = true; while (isRunning) { try { Log.d(TAG, "Timer is running for : " + seconds); seconds++; Thread.sleep(1000); } catch (InterruptedException e) { isRunning = false; } } } public boolean isRunning() { return isRunning; } } } </code></pre> <p>Like I said, these are the relevant code fragments. The problem is, if I run this, the Activity stays black - I just get the header with the name of the app, thats all. With the logging I can confirm that the thread is running, but nothing else is displayed.</p> <p>Can you please help me out, I am rather new to android.<br> Thank you very much - already in advance. </p>
    singulars
    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.
 

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