• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps how to deal with classes in android? help please

kwty

Lurker
Mar 4, 2009
9
0
Hi guys,
I'm working in a project and I want to create a class that has a cursor to retrieve the call log or contacts data and passes them to the main activity or print them or doing anything with them. The problem is when I want to deal with the getContentResolver() and StartManagingCursor(Cursor) they gave me errors. When I do the same application inside the main activity it works fine with me. I tried to extends the activity in the class the error is gone but the program isn't work. I really need to run this application in a separate class and call it inside the main activity so how can I handle this problem ???

The code is as the following:

import java.io.IOException;
import java.io_ObjectOutputStream;
import java.net.Socket;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;

public class CallLog1 {

private ObjectOutputStream out;
public CallLog1(Socket clin) throws IOException{

Socket client = clin;
// Querying for a cursor is like querying for any SQL-Database
Cursor c = getContentResolver().query(
android.provider.CallLog.Calls.CONTENT_URI,
null, null, null,
android.provider.CallLog.Calls.DATE + " DESC");
startManagingCursor(c);

// Retrieve the column-indixes of phoneNumber, date and calltype
int numberColumn = c.getColumnIndex(
android.provider.CallLog.Calls.NUMBER);
int dateColumn = c.getColumnIndex(
android.provider.CallLog.Calls.DATE);
// type can be: Incoming, Outgoing or Missed
int typeColumn = c.getColumnIndex(
android.provider.CallLog.Calls.TYPE);

// Will hold the calls, available to the cursor


// Loop through all entries the cursor provides to us.
if(c.moveToFirst()){
do{
String callerPhoneNumber = c.getString(numberColumn);
int callDate = c.getInt(dateColumn);
int callType = c.getInt(typeColumn);

String type = null;
switch(callType){
case android.provider.CallLog.Calls.INCOMING_TYPE:
type = "Incoming Call";
break;
case android.provider.CallLog.Calls.MISSED_TYPE:
type = "Missed Call";
break;
case android.provider.CallLog.Calls.OUTGOING_TYPE:
type = "Outgoing Call";
break;
}
.... bla bla bla

How can I deal with the Cursor in this case ??

With my best regards.
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones