This question has already been answered:
- Static Class Objects 1 Response
Good I do the service of getting time, which gives it through the interface. The skeleton code is:
public class TimeSyncService extends Service { private static final String TAG = "TimeSyncService"; private static final String NTP_SERVER_IP = "192.168.128.5"; private static final getNtpListenet ntpListener = null; public interface getNtpListenet { void onTimeReceived(String fileName); } @Nullable @Override public IBinder onBind(Intent intent) { return null; } @Override public void onCreate() { super.onCreate(); Log.d(TAG, "onCreate: "); } @Override public void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy: "); } @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; } class JobResult { boolean has_error = false; boolean synced = false; } static class getNtpTime extends AsyncTask<Void, Void, JobResult> { private getNtpListenet listener; @Override protected JobResult doInBackground(Void... voids) { JobResult jobResult = new JobResult(); //ошибка return jobResult; } @Override protected void onPostExecute(JobResult jobResult) { super.onPostExecute(jobResult); listener.onTimeReceived("time here"); } } }
In the line JobResult jobResult = new JobResult (); I get the error "Can not be references from a static context". The meaning of the error is clear, but how to correct it correctly in this case?