码迷,mamicode.com
首页 > 其他好文 > 详细

alarm

时间:2019-04-06 19:15:16      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:activity   new   gets   roi   pre   ext   extends   ice   realtime   

package com.example.alarm;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class RefreshBroadcastReceiver extends BroadcastReceiver {
	public void onReceive(Context context, Intent intent) {
		Toast.makeText(context, "kym I love you", Toast.LENGTH_SHORT).show();
		}
}

  

package com.example.alarm;

import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.app.AlarmManager;

public class MainActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AlarmManager manager = (AlarmManager) getSystemService(ALARM_SERVICE);
		Intent intent2 = new Intent(this, RefreshBroadcastReceiver.class);
		PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent2, 0);
		manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, 100, 100, pi);
    }
}

  

alarm

标签:activity   new   gets   roi   pre   ext   extends   ice   realtime   

原文地址:https://www.cnblogs.com/cuthead/p/alarm.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!