I created an application to call an alarm manager to repeat the task every 1 hours, when the alarm manager is trigger, and I have other function to onReceive the alarm manager.
public void onReceive(Context context, Intent intent) {
loadClassFromAsp();
if (MainActivity.gCountBook >= 1) {
MyNotificationScheduler.showNotification(context, Access.class, "Class Reminder !!", "Don't miss your class on next hour !!");
}
}
public void loadClassFromAsp() {
String Url;
Uri.Builder builder = new Uri.Builder();
builder.scheme("")
.authority("192.168.0.28")
.appendPath("sfitness")
.appendPath("apps")
.appendPath("checkBooking.asp");
Url = builder.build().toString();
MyNotificationReceiver.getBook task = new MyNotificationReceiver.getBook();
task.execute(Url);
}
On the uri builder I have a AsynTask function also
private class getBook extends AsyncTask<String, Void, Void> {
private String responseString = null;
//private ProgressDialog dialog = new ProgressDialog(getContext());
protected void onPreExecute() {
}
protected Void doInBackground(String... urls) {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(Url);
//From this place onwards, my program end and pop error
try {
HttpResponse response = client.execute(request);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
responseString = str.toString();
} catch (ClientProtocolException e) {
responseString = "Error! Client Protocol Exception";
} catch (IOException e) {
responseString = "Please Login Check your Internet connection."; //No Internet Access!
}
return null;
}
protected void onPostExecute(Void unused) {
if (responseString != null) {
String sGetString = responseString.substring(0, responseString.indexOf("|"));
String sGet = responseString.toString();
MainActivity.gCountBook = Integer.parseInt(sGetString);
List classBook = new ArrayList<String>();
for (int i = 0; i < MainActivity.gCountBook; i++) {
sGet = sGet.substring(sGet.indexOf("|") + 1, sGet.length());
String data = sGet.substring(0, sGet.indexOf("|"));
}
}
}
}
On my AsynTask function, after the HttpGet and enter into try, my application pop out and said "Unfortunately, your apps has stopped" This is what I get from debugger. There is no error, nothings. Every time my apps run until the try statement automatically pop out. Anyone know the solution for this ? I have no idea why.
I have similar function that done in other class, that function run flawless I have no idea what is the problem inside. I added receiver in my manifest too.
Thanks, if anything you need me to update please do tell me. Thanks !!