- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Java 的新手,更不用说 Android 开发了。我没有编码背景,但我想我会从像闹钟这样的“简单”东西开始。所以现在我正在写一个闹钟,如果闹钟响起后没有重复,我想将闹钟更新为非 Activity 状态。当我有意向将可打包的 AlarmClass(我的警报对象)传递到警报设置屏幕时,它通过得很好。当我将相同的 AlarmClass 传递给 Intent ,并将其放入警报管理器中的 PendingIntent 中,然后尝试从可以关闭警报的屏幕中获取它时,我正在调用和填充的 AlarmClass 对象完全相同始终为空。
这是我的闹钟类:
package com.example.wakeme;
import java.util.Calendar;
import android.os.Parcel;
import android.os.Parcelable;
public class AlarmClass implements Parcelable{
Calendar cal = Calendar.getInstance();
private long id = 1;
private int active = 1;
private long time = cal.getTimeInMillis();
private int repeating = 0;
private int skipweekends = 0;
private int skipweekdays = 0;
private int alarmnumber = -1;
public long getId(){
return id;
}
public void setId(long id) {
this.id = id;
}
public int getActive(){
return active;
}
public void setActive(int active) {
this.active = active;
}
public int getRepeating(){
return repeating;
}
public void setRepeating(int repeating){
this.repeating = repeating;
}
public void setTime(long time){
this.time = time;
}
public long getTime(){
return time;
}
public int getSkipWeekends(){
return skipweekends;
}
public void setSkipWeekends(int skipweekends){
this.skipweekends = skipweekends;
}
public int getSkipWeekdays(){
return skipweekdays;
}
public void setSkipWeekdays(int skipweekdays){
this.skipweekdays = skipweekdays;
}
public void setAlarmNumber(int alarmnumber){
this.alarmnumber = alarmnumber;
}
public int getAlarmNumber(){
return alarmnumber;
}
@Override
public int describeContents(){
return 0;
}
private AlarmClass(Parcel in){
this.id = in.readLong();
this.active = in.readInt();
this.repeating = in.readInt();
this.skipweekdays = in.readInt();
this.skipweekends = in.readInt();
this.time = in.readLong();
this.alarmnumber = in.readInt();
}
AlarmClass() {
return;
}
public void writeToParcel(Parcel out, int flags) {
out.writeLong(this.id);
out.writeInt(this.active);
out.writeInt(this.repeating);
out.writeInt(this.skipweekdays);
out.writeInt(this.skipweekends);
out.writeLong(this.time);
out.writeInt(this.alarmnumber);
}
public static final Parcelable.Creator<AlarmClass> CREATOR = new Parcelable.Creator<AlarmClass>(){
public AlarmClass createFromParcel(Parcel in){
return new AlarmClass(in);
}
public AlarmClass[] newArray(int size) {
return new AlarmClass[size];
}
};
从这里,我可以将我的对象传递给闹钟 setter 来更新它:
public void startSet(View view){
Intent set = new Intent(this, SetAlarm.class);
set.putExtra("alarm", new AlarmClass());
startActivity(set);
}
我在我的时间 setter 上收到它就很好。它是非空的:
public class SetAlarm extends MainActivity {
AlarmClass passAlarm = new AlarmClass();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.alarm_set);
setAlarmSetListener();
setDeleteListener();
passAlarm = (AlarmClass) getIntent().getParcelableExtra("alarm");
if(passAlarm.getAlarmNumber() != -1){
TimePicker picker = (TimePicker) findViewById(R.id.timePicker1);
Calendar passedTime = Calendar.getInstance();
passedTime.setTimeInMillis(passAlarm.getTime());
picker.setCurrentHour(passedTime.get(Calendar.HOUR_OF_DAY));
picker.setCurrentMinute(passedTime.get(Calendar.MINUTE));
String ampm = (passedTime.get(Calendar.HOUR_OF_DAY) > 12 ? "pm" : "am");
String message = "Passed Time is: " + (passedTime.get((Calendar.HOUR_OF_DAY)%12)!=0?(passedTime.get(Calendar.HOUR_OF_DAY)%12):12) + ":" + passedTime.get(Calendar.MINUTE) + " " + ampm;
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
}
else{
// Do Nothing
}
}
但是当这样通过 PendingIntent 发送时:
private void newAlarm(AlarmClass alarmclass){
Intent intent = new Intent(getBaseContext(), Alarm.class);
intent.putExtra("alarm", alarmclass);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(alarmclass.getTime());
AlarmsDataSource alarm = new AlarmsDataSource(this);
alarm.open();
AlarmClass alarmObject = new AlarmClass();
alarmObject = alarm.createAlarm(true, cal.getTimeInMillis(), false, false, false);
PendingIntent torpedo = PendingIntent.getBroadcast(this,alarmObject.getAlarmNumber(),intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager goOff = (AlarmManager) getSystemService(ALARM_SERVICE);
goOff.set(AlarmManager.RTC_WAKEUP, alarmObject.getTime() ,torpedo);
Toast.makeText(getApplicationContext(), "Alarm Number " + alarmObject.getAlarmNumber(), Toast.LENGTH_LONG).show();
alarm.close();
}
并以同样的方式收到警报 Activity :
public class Boom extends MainActivity{
AlarmClass boomAlarm = new AlarmClass();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Window wake = getWindow();
wake.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
setContentView(R.layout.boom);
setTheme(R.style.AlarmStyle);
overridePendingTransition(android.R.anim.fade_in,5000);
boomAlarm = (AlarmClass) getIntent().getParcelableExtra("alarm");
// Vibrator buzz = (Vibrator) getSystemService(VIBRATOR_SERVICE);
// buzz.vibrate(1000);
snoozeListener();
dismissListener();
}
我传递给 boomAlarm 的可打包对象始终为空。
有谁知道为什么一个 parcelable 对象在 intent 中工作得很好,但在 PendingIntent 的另一边却变成 null?
最佳答案
听起来您遇到的问题类似于 ClassNotFoundException when using custom Parcelable
https://code.google.com/p/android/issues/detail?id=6822 中描述了一种解决方法并回答ClassNotFoundException when using custom Parcelable
关于android - getParcelableExtra 在 Pending Intent 上总是 null,但不是 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19215661/
因此控制台中的结果显示为 - Promise { } ' why is it still pending?' [ { _id: 5a7c6552380e0a299fa752d3, username:
据我所知,这两种设置都做同样的事情:当请求在待处理队列中花费的时间超过该设置所说的时间时,启动一个新实例。 The maximum amount of time that App Engine sh
我在进行 Entity Framework 代码优先迁移时经常遇到以下情况。我添加了一些迁移,并成功地用它们更新了数据库。稍后,当我希望添加新的迁移时,Add-Migration命令会提示其“无法生成
就我而言,我能够获取 token ,但不是我想要的方式,即我不想打印待处理的 promise ,并且在 tokenDisp.js 中运行后的输出是: output: Promise { pending
async function db(path){ const res = await fetch('data.json'); const data = await res.json();
我有一个具有PV,Service和2 Pod statefulset(包括动态PVC)的文件。 部署文件时,PVC状态发生了问题。 # kubectl get pvc NAME
我在 Azure 数据工厂服务中创建了一些管道,以将数据从 SQL 表移动到 Azure 表。但他们从不开始运行。相反,即使在我单击 Azure 门户中的运行 按钮后,源数据集仍然处于待验证状态。我已
将新的开发人员添加到启用沙盒的应用程序会在受邀的 Facebook 用户旁边显示“待处理”,并且用户永远不会收到确认电子邮件或任何允许他确认将自己添加为开发人员的信息。以前有没有人遇到过这个问题。我发
我在我的网上商店中集成了 PayPal,以便通过自动产品交付实现即时付款(之前已经有过,但仅限于通过 sofort.com 进行即时电汇)。我在 PayPal 提供的示例的帮助下集成了它(我使用的是
我有一个运行前台服务的应用程序。该应用程序有一个启动/停止按钮作为其通知的一部分,可以猜到启动和停止前台服务。单击开始按钮后,将触发一个待处理的 Intent。 考虑以下场景: 应用程序已被销毁[从最
所以, 我对 JBehave 有一种奇怪的行为。我有一个场景,我需要一个 StepDef 结构,如下所示: Given some precondition When something happens
我以前从未遇到过这样的事情,所以我希望其他人能够向我解释一下。 我正在开发一个包含一些 Adsense 横幅的网站。为了防止它们出现在我的本地主机或任何测试帐户上,我创建了一些服务器端代码来生成和
我正在学习散列字符串密码并将它们存储在对象列表中。 const bcrypt = require('bcrypt') var users = [] async function hashPass(pa
我正在遵循 Fedora 入门指南 ( https://github.com/GoogleCloudPlatform/kubernetes/blob/master/docs/getting-start
我有一个更新密码功能,可以更新用户的密码并删除生成的一次性 URL。目前,它向前端和变量 updatedResult 返回空响应。说 promise 待定,所以这似乎是空响应的问题。当我执行代码时,这
我在使用 cert-manager 处理 tls 证书时遇到了问题,我正在关注文档并添加了一些额外内容以使用 Traefik作为入口。 目前,我有这个 YAML文件: cluster-issuer.y
我正在创建一个简单的辅助函数,它使用bcrypt返回给定密码的哈希值。但每次我调用该函数时,它都会解析为 Promises { }我做错了什么? const saltPassword = async
这个问题已经有答案了: How do I return the response from an asynchronous call? (42 个回答) 已关闭 4 年前。 JS 新手,我正在尝试理解
我正在为一个项目构建一个 CRUD 应用程序,人们可以添加查看和删除条目,我为此使用nodejs、js 和 fireabse。我有这样的 firestore 数据库结构: entries: --
我的服务器端有以下代码: // Bind to a specific local port number (SERVER_PORT) and any local IP address. m_tlSer
我是一名优秀的程序员,十分优秀!