我有一个半透明的活动,我想在最初按下按钮后每分钟开始一次。此活动包含一行文本,我只想显示即使用户已关闭应用程序,也不会中断用户当前的活动(应该在后台显示。到目前为止,我可以启动活动,但它会停止当前活动和背景是我自己的应用程序中的另一项活动
以下是我创建的警报类:
public void startAlarm(Context context) {
if (Build.VERSION.SDK_INT < 19) {
Intent intent = new Intent(context, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + (1000 * 60),
pendingIntent);
} else {
Intent intent = new Intent(context, MyBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + (1000 * 60),
pendingIntent);
}
}
现在我的广播接收器类:
@Override
public void onReceive(Context context, Intent intent) {
// Start service
Intent service = new Intent(context, MyService.class);
context.startService(service);
// Schedule next alarm
alarm.startAlarm(context);
}
现在开始活动的服务:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Start ad activity
Intent activity = new Intent(context, MainActivity.class);
activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(activity);
stopSelf();
return START_STICKY;
}
这是我的manifest.xml,显示了有问题的活动:
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/Theme.FullTransparent" />
我申请的风格:
<style name="Theme.FullTransparent" parent="AppTheme.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:backgroundDimEnabled">true</item>
</style>
任何帮助将不胜感激。提前谢谢!