简体   繁体   中英

Display toast message after six months from the date of registration

I want to display a toast message in my app after six months from the user's registration date

For example, a user registered on 2018/04/20 i want show toast message on 2018/10/20

that's mean, after 6 months from the date of registration

in php i can use this command SELECT * FROM events WHERE event_date >= DATE(NOW() + INTERVAL 6 MONTH) - in sqlite what can I do?

first create a subclass of BroadcastReceiver :

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle=intent.getExtras();
        if (bundle!=null) {
            String key=bundle.getString("MyKey");
            if (key.equals("my_key")){
                Toast.makeText(context, "your message" , Toast.LENGTH_SHORT).show();
            }
        }   
    }
}

then you need to create Calendar and AlarmManager :

Calendar calendar=Calendar.getInstance();
calendar.add(Calendar.MONTH, here insert your mount number "for exam 6 for 6 mount later ");
AlarmManager alarmManager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
 Intent intent=new Intent(MainActivity.this,MyReceiver.class);
intent.putExtra("MyKey","my_key");
long futureInMillis = calendar.getTimeInMillis();
PendingIntent pendingIntent=PendingIntent.getBroadcast(MainActivity.this,0,intent,0);
alarmManager.set(AlarmManager.RTC_WAKEUP,futureInMillis,pendingIntent);

and in manifest add this :

<receiver android:name=".MyReceiver"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM