עבור לתוכן
View in the app

A better way to browse. Learn more.

HWzone

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

ניסיון ליצירת טיימר באנדרואיד

Featured Replies

פורסם

היי אנשים, כחלק מאפליקציה שאני עובד עליה עכשיו אני צריך ליצור טיימר פשוט. ניסיתי לעשות זאת כך:





private void starTimer() {
// TODO Auto-generated method stub
new AsyncTask<Integer, Void, Boolean>() {


@Override
protected Boolean doInBackground(Integer... params) {

try {
Thread.sleep(params[0]);
} catch (InterruptedException e) {
e.printStackTrace();
}


return true;
}


@Override

protected void onPostExecute(Boolean result) {
while(true)
{
sec++;
showTime();
if(sec==60)
{
min++;
sec=0;
showTime();
}
if(min==60)
{
hr++;
min=0;
showTime();
}
}
}

}.execute(1000);


}


private void showTime() {
// TODO Auto-generated method stub
tvTimer.setText(hr + ":" + min + ":" + sec);
}


הבעיה שהטיימר לא משתנה ואחרי כמה שניות זה מעיף אותי מהאפליקציה.

יש הצעות?

תודה ושבוע טוב.

שחר. :hat:

פורסם

אתה לא משתמש נכון ב-AsyncTask. ראה דוגמה נכונה כאן:

http://developer.android.com/reference/android/os/AsyncTask.html

בשביל לשלוח עדכונים לטיימר אתה צריך לדרוס את הפונקציה onProgressUpdate, והפונקציה doInBackground צריכה לקרוא כל כמה זמן ל-publishProgress. הפונקציה onPostExecute נקראת רק פעם אחת בסיום העבודה (כש-doInBackground מסיימת לרוץ).

  • 2 חודשים מאוחר יותר...

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.