Java中的内部类和静态嵌套类之间的主要区别是什么?设计/实施是否在选择其中一个方面发挥作用?
我是Kotlin的新手,也是使用intentService的一点点堆栈.Manifest向我显示一个错误,我的服务不包含默认构造函数,但在服务内部它看起来没问题且没有错误.
这是我的intentService:
class MyService : IntentService {
constructor(name:String?) : super(name) {
}
override fun onCreate() {
super.onCreate()
}
override fun onHandleIntent(intent: Intent?) {
}
}
Run Code Online (Sandbox Code Playgroud)
我还尝试了另一种变体:
class MyService(name: String?) : IntentService(name) {
Run Code Online (Sandbox Code Playgroud)
但是当我尝试运行此服务时,我仍然会收到错误:
java.lang.Class<com.test.test.MyService> has no zero argument constructor
Run Code Online (Sandbox Code Playgroud)
任何想法如何修复Kotlin中的默认构造函数?
谢谢!
我知道如何在一些点击事件后X毫秒开始通知.像这样的代码
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
triggerNotification();
}
};
timer.schedule(timerTask, 3000);
Run Code Online (Sandbox Code Playgroud)
通知代码如下所示
CharSequence title = "Hello";
CharSequence message = "Hello, Android!";
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon, "A New Message!", System.currentTimeMillis());
Intent notificationIntent = new Intent(this, AndroidAlarmService.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(AndroidAlarmService.this, title, message, pendingIntent);
notification.defaults = Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)
如何设置通知在特定时间出现在特定日期,比如10月1日晚7点?