Having the following code, I have solved a problem.
app class
import android.app.Application;
import android.content.Context;
public class App extends Application {
private static Application myApplication;
public static Application getApplication() {
Application sApplication = new Application();
return sApplication;
}
public static Context getContext() {
return getApplication().getApplicationContext();
}
@Override
public void onCreate() {
super.onCreate();
myApplication = this;
}
}
newInstance within snippet.
public static Categories newInstance(int index,CheckBox check) {
Categories categories = new Categories();
java.util.Calendar now = java.util.Calendar.getInstance();
TimePickerDialog tpd = new TimePickerDialog(
App.getContext(),
now.get(java.util.Calendar.HOUR_OF_DAY),
now.get(java.util.Calendar.MINUTE),
check.isChecked()
);
But now I have the disadvantage that when I call the App.getContext () context in this way when passing the parameters, it shows me the following error:
Can not resolve constructor 'TimePickerDialog (android.content.context, int, int, boolean)'
EYE I call it this way because if I use this, getContext () or Categories.this tells me that you can not reference a context within a static method.