startManagingCursor() in a service?

后端 未结 2 899
名媛妹妹
名媛妹妹 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: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();
    
    }
    

提交回复
热议问题