Alarmdemo
来源:互联网 发布:windows如何多线程 编辑:程序博客网 时间:2024/06/15 04:57
package com..alarmdemo;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
private AlarmManager mAlarmManager;
private PendingIntent mOperation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 闹钟管理器
mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent();
intent.setAction("xxx.yyy.zzz");
mOperation = PendingIntent.getBroadcast(getApplicationContext(), 101, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
public void start(View v) {
// 参1: 事件类型
// 每隔多长时间, 做一件事
mAlarmManager.setRepeating(AlarmManager.RTC, 0, 3000, mOperation);
}
public void stop(View v) {
// 停止, 用户清理应用时, 不会停止
mAlarmManager.cancel(mOperation);
}
}
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.itheima.alarmdemo08.AlarmReceiver">
<intent-filter >
<action android:name="xxx.yyy.zzz"/>
</intent-filter>
</receiver>
</application>
package com..alarmdemo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG = AlarmReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "定时器...");
}
}
package com..alarmdemo;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
private AlarmManager mAlarmManager;
private PendingIntent mOperation;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 闹钟管理器
mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent();
intent.setAction("xxx.yyy.zzz");
mOperation = PendingIntent.getBroadcast(getApplicationContext(), 101, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
public void start(View v) {
// 参1: 事件类型
// 每隔多长时间, 做一件事
mAlarmManager.setRepeating(AlarmManager.RTC, 0, 3000, mOperation);
}
public void stop(View v) {
// 停止, 用户清理应用时, 不会停止
mAlarmManager.cancel(mOperation);
}
}
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="com.itheima.alarmdemo08.AlarmReceiver">
<intent-filter >
<action android:name="xxx.yyy.zzz"/>
</intent-filter>
</receiver>
</application>
package com..alarmdemo;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class AlarmReceiver extends BroadcastReceiver {
private static final String TAG = AlarmReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
Log.i(TAG, "定时器...");
}
}
0 0
- Alarmdemo
- JavaScript-条件语句
- HDU 1251 统计难题(map)
- java的(PO,VO,TO,BO,DAO,POJO)解释
- redis的安装及php的redis使用
- 共享存储NFS
- Alarmdemo
- java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool
- Screen position out of view frustum解决办法
- hibernate学习
- 英文版Ubuntu16.04安装fcitx-googlepinyin
- java 读取properties文件
- nohup不输出日志信息的方法及linux重定向
- NYOJ取石子(一)23题
- 在office中嵌入mathtype