题目内容

从Android 8.0系统开始,如果希望Service不会由于系统内存不足而导致被回收,可以使用____________服务,处在这种状态的Service会有一个正在运行的图标在状态栏显示,类似于通知的效果。

查看答案
更多问题

从Android 9.0开始,使用前台服务,必须在AndroidManifest.xml文档中申请使用相应权限:

请根据注释的空白划线处填写合适内容。// 自定义的IntentService类public class MyIntentService(1)________________________ {// 自定义类的构造方法(2)________________________ {//调用超类的构造方法,并传入字符串参数"MyIntentService"(3)________________________;}// IntentService的处理Intent工作队列后台线程方法@Overrideprotected void (4)________________________ (Intent intent) {// 在Logcat窗口中电灯泡当前线程的idLog.d("MyIntentService", "Thread id is " + (5)________________________);}…}

下面是一个需要绑定服务的Activity类程序片断,阅读程序后简述该类主要编程逻辑。public class MainActivity extends Activity implements OnClickListener {private Button bindService;private Button unbindService;private MyService.DownloadBinder downloadBinder;private ServiceConnection connection = new ServiceConnection() {@Overridepublic void onServiceDisconnected(ComponentName name) {}@Overridepublic void onServiceConnected(ComponentName name, IBinder service) {downloadBinder = (MyService.DownloadBinder) service;Log.d("MainActivity", "onServiceConnected!");downloadBinder.startDownload();downloadBinder.getProgress();}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);bindService = (Button) findViewById(R.id.bind_service);unbindService = (Button) findViewById(R.id.unbind_service);bindService.setOnClickListener(this);unbindService.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.bind_service:Intent bindIntent = new Intent(this, MyService.class);bindService(bindIntent, connection, BIND_AUTO_CREATE);break;case R.id.unbind_service:unbindService(connection);break;default:break;}}}

阅读下面程序片断,请说明IntentService类运行逻辑。public class MyIntentService extends IntentService {public MyIntentService() {super("MyIntentService");}@Overrideprotected void onHandleIntent(Intent intent) {Log.d("MyIntentService", "Thread id is " + Thread.currentThread().getId());}@Overridepublic void onDestroy() {super.onDestroy();Log.d("MyIntentService", "onDestroy executed");}}

答案查题题库