>From my MainActivity the user can click a button that shows a dialog.
>From this dialog the user can set the number of minutes and number of
seconds from a custom Timer component, and click a start button. When
they click start, this is the OnClickListener that gets invoked.

   public void onClick(DialogInterface dialog, int whichButton) {
        AlertDialog alertDialog = (AlertDialog)dialog;
        Timer timer = (Timer)alertDialog.getWindow().findViewById
(R.id.timer);

        Intent intent = new Intent(MainActivity.this,CountDown.class);
        intent.putExtra(KEY_MINUTES, timer.getMinutes());
        intent.putExtra(KEY_SECONDS, timer.getSeconds());
        startActivity(intent);
        //startActivityForResult(intent, ACTIVITY_COUNT_DOWN);
   }

As you can see it is sent to the CountDown activity. What is supposed
to happen is the minutes and seconds that the user selected from the
dialog are displayed on the CountDown screen, and they begin to count
down and an explosion sound is played when zero is reached. What is
really happening, For some reason the screen goes black, and nothing
is displayed, however the explosion is played 30 seconds later if user
selected 30 seconds. The CountDown Activity has two methods onCreate
and  onWindowFocusChanged. OnCreate is used to set up the view and
onWindowFocusChanged is used to count down and update the view as each
second pasts. I put the count down code in the  onWindowFocusChanged
because it there is no user intervention except to watch the time
count down, and according to the android documentation this is the
best indicator that the activity is visible to the user.http://
code.google.com/android/reference/android/app/
Activity.html#onWindowFocusChanged(boolean). See my code below.


   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.count_down);

       //instantiate the components
       mMinutesText = (TextView)findViewById(R.id.count_down_minutes);
       mSecondsText = (TextView)findViewById(R.id.count_down_seconds);
       cancelButton = (Button)findViewById(R.id.count_down_cancel);

       Bundle extras = getIntent().getExtras();
       mMinutes = extras.getInt(KEY_MINUTES);
       mMinutesText.setText(mMinutes);

       mSeconds = extras.getInt(KEY_SECONDS);
       mSecondsText.setText(mSeconds);

       cancelButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                mIsCountingDown = false;
        setResult(RESULT_OK,new Intent());
        finish();
            }
        });
}

@Override
public void onWindowFocusChanged(boolean hasFocus){
    super.onWindowFocusChanged(hasFocus);
    if(hasFocus){
        countDown(mMinutes,mSeconds);
        if(mMinutes == 0 && mSeconds == 0){
        MediaPlayer mp = MediaPlayer.create(this, mSound);
        mp.start();
        }

        Intent mIntent = new Intent();
        setResult(RESULT_OK,mIntent);
        finish();
     }
}


Here are logs from LogCat. I am wondering if this "Launch timeout has
expired, giving up wake lock!" is the problem. If this is the problem
then what is causing it

12-30 02:40:31.926: INFO/ActivityManager(53): Displayed activity
com.android.myapp/.CountDown: 14992 ms
12-30 02:41:40.408: INFO/ActivityManager(53): Starting activity:
Intent { comp={com.android.myapp/com.android.myapp.CountDown} (has
extras) }
12-30 02:41:50.454: WARN/ActivityManager(53): Launch timeout has
expired, giving up wake lock!
12-30 02:41:50.549: WARN/ActivityManager(53): Activity idle timeout
for HistoryRecord{43524f10 {com.android.myapp/
com.android.myapp.CountDown}}
12-30 02:42:00.166: INFO/ActivityManager(53): Displayed activity
com.android.myapp/.CountDown: 19743 ms

Any guidance someone can provide would be very helpful.

Skooter :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to