Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
How to set specific time in Toast?

Can I display a toast message based on user's current time?

I need to make an app, Where when I open the screen from 1:00 am to 11:00 am it will display the toast message "Good morning" whereas if I open the screen at 6:00 pm to 11:00 pm it will display the toast "good night"

public class ToastDisplay extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)){
            Toast.makeText(context,"Good Morning",Toast.LENGTH_SHORT).show();
        }
    }
}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

int toastDurationInMilliSeconds = 10000;

Toast.LENGTH_SHORT is int, so you have to declare new int

over 4 years ago · Santiago Trujillo Report

0

What you can do i use Calendar class to get the current time. Check the time and display the toast accordingly.

Calendar currentTime = Calender.getInstance();
int hour = currentTime.get(Calendar.HOUR_OF_DAY);

if(Use your condition here) {
    Display toast
} else if(Use your other condition) {
    Display toast
}

Just a note, your hour would be in 24 hour format so you need to check keeping that in mind.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!