-1
これは私が作成したサービスクラスのコードです。これは、handler.post(timedtask)行でUnreachableコードのエラーを返します。私は下の太字でコメントしています。これで私を助けてください。その私を殺す!
パブリッククラスServerCheckerはサービスを拡張します。{ NotificationCompat.Builder mBuilder; インテントresultIntent; ハンドラハンドラ。 実行可能なタイム・タスク。 文字列bus_no; int mystoppageindex;Handlerステートメントが邪魔にならないコードはなぜですか?
public ServerChecker() {
}
@Override
public void onCreate() {
super.onCreate();
bus_no = PrefsHelper.getFromPreferences(MyApplication.getAppContext(), "BUSNO", "");
mBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setTicker("Your bus is arriving")
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true);
resultIntent = new Intent(this, LoginActivity.class);
String url = Config.url + "arrivalwarning.php?bus_no=3-C";
final StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mystoppageindex = Integer.parseInt(PrefsHelper.getFromPreferences(MyApplication.getAppContext(), "STOPPAGEINDEX", ""));
try {
JSONObject jsonObject = new JSONObject(response);
int currentstoppageindex = Integer.parseInt(jsonObject.getString("stoppage_index"));
if (mystoppageindex - currentstoppageindex == 2) {
TaskStackBuilder stackBuilder = TaskStackBuilder.create(MyApplication.getAppContext());
stackBuilder.addParentStack(LoginActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
handler = new Handler();
timedtask = new Runnable() {
@Override
public void run()
{
Log.d("TAG","Runnable");
// VolleySingleton.getInstance().getRequestQueue().add(request);
handler.postDelayed(timedtask, 60000);
}
};
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
handler.post(timedtask); **// WHY IS THIS LINE AN ERROR UNREACHABLE CODE**
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onDestroy() {
super.onDestroy();
handler.removeCallbacks(timedtask);
}
}
を "なぜこの行にエラーがありませんか? " - あなたは' return'ステートメントの後にそれを持っているからです。その前に移動してください。 –