如何在Activity中启动服务?
我尝试调用:
Notification notification = new Notification(R.drawable.ic_launcher, getText(R.string.app_name),System.currentTimeMillis());
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.app_name),getText(R.string.app_name), pendingIntent);
startForeground(1, notification);
然而,它会显示"Cannot resolve method 'startforeground(int, android.app.Notification)'"。
我该怎么调用startForeground方法呢?我尝试使用getApplicationContext()但没有成功。
startForeground()
方法时,才使用它们。 - CommonsWare