logo
down
shadow

Turn on the screen when timer calls onFinish()


Turn on the screen when timer calls onFinish()

By : Alan Maik
Date : November 22 2020, 03:01 PM
wish help you to fix your issue This needs to be done in a different way then what I was thinking.
What needs to be done is a new activity needs to be created from an alarm.
code :
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
public class ReceiverAlarm extends BroadcastReceiver {
private AlarmManager alarmMgr;
private PendingIntent alarmIntent;

//This is what will be called when your alarm goes off
@Override
public void onReceive(Context context, Intent intent) {
    Log.d("Logged", "ReceiverAlarm");
    Intent i = new Intent(context, ScreenWake.class);
    context.startActivity(i);
}

//This is a method I made that will set an alarm
public void setAlarm(Context context, int timeToPop) {
    alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, ReceiverAlarm.class);
    alarmIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    long currentTime = SystemClock.elapsedRealtime();
    long timeToAdd = (long) timeToPop;
    alarmMgr.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            currentTime + timeToAdd, alarmIntent);
}

public void cancelAlarm(Context context) {
    Intent intent = new Intent(context, ReceiverAlarm.class);
    PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(sender);
}
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_alarm_wakes_screen);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON |
            WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

    ms = new ManagerSound(getApplicationContext());
    ms.playAlarm();
}


Share : facebook icon twitter icon
Will serial calls to Threading.Timer.Change() reset the timer's clock?

Will serial calls to Threading.Timer.Change() reset the timer's clock?


By : WayneJ
Date : March 29 2020, 07:55 AM
I wish this help you It will run in 5 seconds. Calling Change will Reset the initial Count.
Turn Off Sound and screen blink on incoming calls in Android?

Turn Off Sound and screen blink on incoming calls in Android?


By : Elizabeth Edrada
Date : March 29 2020, 07:55 AM
CountDownTimer's OnFinish() fires when the timer is Halfway in its countdown

CountDownTimer's OnFinish() fires when the timer is Halfway in its countdown


By : Strwind
Date : March 29 2020, 07:55 AM
I hope this helps . I've used a CountDownTimer in an android project, and what happens, is, my OnFinish() fires while the CountDown is in its half way stage. , I've solved the problem.
code :
public void ShowNotice(){
        cdt = new CountDownTimer(20000, 2000) {

            @Override
            public void onTick(long millisUntilFinished) {
                // TODO Auto-generated method stub
                Toast toast = Toast.makeText(con,"Game Starts In :"+String.valueOf(millisUntilFinished/2000),
                        Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.BOTTOM, 0, 0);
                toast.show();
            }

            @Override
            public void onFinish() {
                // TODO Auto-generated method stub
                Toast toast = Toast.makeText(con,"Game Starts Now!",
                        Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.BOTTOM, 0, 0);
                toast.show();
                RemoveButtonText();
            }
        };

        cdt.start();
    }
cdt = new CountDownTimer(20000, 2000)
The screen of Toast information is still displayed after I call mMediaRecorder.start() in the function onFinish() in Cou

The screen of Toast information is still displayed after I call mMediaRecorder.start() in the function onFinish() in Cou


By : smurf
Date : March 29 2020, 07:55 AM
help you fix your problem According to android documentation. Toast.LENGTH_SHORT will display the toast for 2 second.
code :
private static final int SHORT_DELAY = 2000; // 2 seconds
 private Toast mToastText;     
 private void DelayStartRecord(RecordArg mRecordArg){
                new  CountDownTimer(10*1000, 1000) {

                public void onTick(long millisUntilFinished) {
                    String s="seconds remaining: " + millisUntilFinished / 1000;
                    if(mToastText==null){
                       mToastText = Toast.makeText(activity, "", Toast.LENGTH_SHORT);
                    }                    
                    mToastText.setText(s);
                    mToastText.show();
                }

                public void onFinish() {
                    if(mToastText!=null){
                      mToastText.cancel();
                    }
                    mMediaRecorder.start();
                }

            }.start();
    }
Count down timer how to implement onfinish method

Count down timer how to implement onfinish method


By : Lubna
Date : March 29 2020, 07:55 AM
around this issue You can use CountDownTimer:
code :
new CountDownTimer(endsIn * 1000, 1000) { 
public void onTick(long millisUntilFinished) { 
           timerTextView.setText(String.valueOf(millisUntilFinished/1000);
 } 
public void onFinish() {
} 
}.start();
public class countdown_timer extends CountDownTimer {
    TextView textView;
    @Override
    public void onTick(long millisInFuture) {
        long sec = millisInFuture/1000;
            if(millisInFuture <= 0) {
                Log.v("status", "done");

        } else {
            Log.v("status", Long.toString(sec) + " seconds remain and timer has stopped!");
        }
    }

    @Override
    public void onFinish() {
        if(textView != null){
            // change text in your textview
        }
    }



    public countdown_timer(long pMillisInFuture, long pCountDownInterval) {
        super(pMillisInFuture, pCountDownInterval);

    }
    public countdown_timer(TextView textView, long pMillisInFuture, long pCountDownInterval) {
        super(pMillisInFuture, pCountDownInterval);
        this.textView = textView;




    }






}
public class MainActivity extends AppCompatActivity {

    TextView textView;
    CountDownTimer mycounterdown;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        long startcard = 10000;
        textView = (TextView) findViewById(R.id.test);

        mycounterdown = new CountDownTimer(startcard, 1000) {
            @Override
            public void onTick(long mycounterup) {
                int minutes_up_start = (int) (mycounterup / 1000) / 60;
                int seconds_up_start = (int) (mycounterup / 1000) % 60;
                String time_2_up_start_formatted = String.format(Locale.getDefault(), "%02d:%02d", minutes_up_start, seconds_up_start);
                textView.setText(time_2_up_start_formatted);
            }

            @Override
            public void onFinish() {
                // call here other methods from activity

                testMethod();
            }
        };
        mycounterdown.start();

    }
    public void testMethod(){
        Toast.makeText(MainActivity.this, "Test Method called", Toast.LENGTH_SHORT).show();
    }

}
public class MainActivity extends AppCompatActivity {

    TextView textView;
    CountDownTimer mycounterdown;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        long startcard = 10000;
        textView = (TextView) findViewById(R.id.test);

        mycounterdown = new CountDownTimer(startcard, 500) {
            @Override
            public void onTick(long mycounterup) {
                int minutes_up_start = (int) (mycounterup / 1000) / 60;
                int seconds_up_start = (int) (mycounterup / 1000) % 60;
                String time_2_up_start_formatted = String.format(Locale.getDefault(), "%02d:%02d", minutes_up_start, seconds_up_start);
                textView.setText(time_2_up_start_formatted);
            }

            @Override
            public void onFinish() {
                // call here other methods from activity

                testMethod();
            }
        };
        mycounterdown.start();

    }
    public void testMethod(){
        Toast.makeText(MainActivity.this, "Test Method called", Toast.LENGTH_SHORT).show();
    }

}
Related Posts Related Posts :
  • ZXing not calling onActivityResult, When scanning QR Code
  • Integration of Android Native module with existing Xamarin Native Project
  • Restore RecyclerView state after rotating
  • ViewModelProviders java.lang.RuntimeException trying to instantiate class which inherit AndroidViewModel
  • SKD19 vs SDK24 - Usage of API documented as @since 1.8+
  • filter option in list view fragment activity
  • Picture from camera not showing up in second activity
  • How to change imageview according to screen size
  • How to copy Android Studio project to remote Git (NOT GitHub) server
  • How to get React-Native to announce specific accessibility message via AccessibiliyManager?
  • Change colors of com.tech.freak.wizardpager.ui.StepPagerStrip
  • Android fullscreen activity shows ActionBar
  • Would like a bit of clarification with SQLite database's onUpgrade method
  • Use ObjectBox with Libgdx
  • How to make combine Gregorian and Hijri calendar in Android?
  • Try to read text file from sdcard in other language
  • "App not installed" message when installed apk
  • How to execute a designated test suite class in Firebase Test Lab
  • play music with background service
  • background not visible on LG G3
  • should every View have an id?
  • Realm object server sync on low connection.
  • Correct way to add more views to adapter
  • Getting error in android support library
  • Instant app zip uploading error
  • "No emulator installed" error in Android Studio even though Intel HAXM is up and running
  • AsyncTask without leaks
  • SQLiteException : No such table found whereas a table was created
  • Using @Component.Builder with constructor params
  • No injector was found for fragment dagger 2.11
  • Android Volley Https SSL self signed and Google Maps API
  • Why does the onClickListener not work anymore in this example?
  • Why are my map marker ObjectAnimators getting canceled?
  • Android App update only working after deleting all local data
  • Getting unknown attribute error in android studio
  • How to remove space in Toolbar
  • Phonegap - Push notification with embedded web app (InAppBrowser window)
  • Broadcast receiver is not triggered for incoming calls
  • How to know whether realm.commitTransaction() succefull
  • How to create title bar in android?
  • Control RecyclerView inflated views from outside the adapter: keep selection state
  • How to swap items from two recyclerview items that are in two fragments in one activity?
  • Having trouble with interfaces in Java regarding retrieval and storage of data from a Firebase Database
  • ViewPager overlaps AppBarLayout
  • Custom view downcasting not working
  • New release on Google Play Store - Keystore was tampered with
  • How do I display items in a RecyclerView one by one onButtonClick instead of loading all questions at once
  • Why use inline without lambdas
  • Retrofit2 - Expected BEGIN_ARRAY but was BEGIN_OBJECT using Call<List<JSONObject>>
  • Notification icon showing up in status bar but not in notification itself
  • Method Not Allowed (405) while uploadFileTask to QuickBlox - (Android)
  • how get Drawable from String path?
  • Why do the ":" not sit on the top in layout files?
  • How do I differentiate between two WhatsApp messages?
  • UTF-8 in Android compared to definition of UTF-8
  • Gradle 3.0 BuildException cannot create directory
  • How to make a screen not fall asleep if the app runs on boot?
  • Share PDF from assets. FileUriExposedException
  • Vertical ViewPager with HorizontalScrollView inside Fragment
  • Adding subscribeOn() is changing return type of observable
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org