java – 在Activity中启动前台服务
发布时间:2020-12-15 04:23:57 所属栏目:Java 来源:网络整理
导读:如何在Activity中启动服务? 我试着打电话: Notification notification = new Notification(R.drawable.ic_launcher,getText(R.string.app_name),System.currentTimeMillis()); Intent notificationIntent = new Intent(this,MainActivity.class); PendingI
如何在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,notificationIntent,0); notification.setLatestEventInfo(this,pendingIntent); startForeground(1,notification); 但是,它“无法解析方法’startforeground(int,android.app.Notification)’” 如何调用startForeground?我试过getApplicationContext()无济于事. 解决方法
调用startService().
startForeground()是Service上的一个方法.您的服务需要自己调用startForegrond()(例如,在服务的onCreate()中). (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |