I have Main class and it contains function isSyncAllowed. I start another service. How to call function isSyncAllowed from this service?
It says:
Cannot make a static reference to the
non-static method
isSyncAllowed(Boolean) from the type
Main
If I change type of that function to static and pass context, I come to the problem that startManagingCursor can not be static.
How can I fix it?
Upd. Here is the code of SyncService:
public class SyncService extends BroadcastReceiver {
...
public void onReceive(Context context, Intent intent) {
...
Boolean isDownloadAllowed = Kinobaza.isSyncAllowed(true);
}
and here is the code of Main:
public class Kinobaza extends ListActivity {
...
public static Boolean isSyncAllowed(Boolean showToasts) {
...
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor); // here is the error
}
}
You are probably doing
Main.isSyncAllowed(...)instead ofmain.isSyncAllowed(...), wheremainis an object of classMain.If you are inside an instance method of
Main, then you can simply doisSyncAllowed(...).Edit – now that I see your code, you should probably pass
isSyncAllowedvia theIntentyou give to the service. When you start the service:and then in your service you can retrieve it:
Your service shouldn’t need to call instance methods on your activities.