startManagingCursor() in a service?

后端 未结 2 853
名媛妹妹
名媛妹妹 2021-01-16 07:23

Is there a way to use the startManagingCursor() within a service instead of an activity, with the same results (as shown here)?

More specifically, i would like to ma

相关标签:
2条回答
  • 2021-01-16 07:38

    Is there a way to use the startManagingCursor() within a service instead of an activity, with the same results

    No, sorry.

    Is it feasible by using an other appropriate method implemented in the Service.class?

    No.

    Is it feasible in some other way?

    You are welcome to write your own support code to do whatever you want. I doubt you can implement what you're seeking, though.

    Or, is it pointless at all?

    IMHO, yes. Having a Cursor be automatically closed when the service is destroyed is not a bad idea. However, the notion of the deactivate()/requery() makes little sense to me in a service. This is also the impossible part, in that you have no place to put the deactivated Cursor that will be picked up by some future incarnation of your service.

    0 讨论(0)
  • 2021-01-16 07:54

    Its possible, you just need to Cast it to Activity

    Like below ((Activity) context).startManagingCursor(cursor);

    Here is the complete code

    private void getUserId(Context context) {
    
         AdapterClass adapterClass = new AdapterClass(this,
         DatabaseDetail.TABLE_USER_REGISTRATION);
         adapterClass.Open();
    
         Cursor cursor = adapterClass.fetchRecords(new String[]{"USER_OID"},
         null);
         if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
         ((Activity) context).startManagingCursor(cursor);
         }
         cursor.moveToFirst();
    
         adapterClass.close();
    
    }
    
    0 讨论(0)
提交回复
热议问题