Snake game in Java but my restart button does not work

Introduction I copied your code into my Eclipse IDE and ran it as is. I received the following runtime error. Exception in thread “main” java.awt.IllegalComponentStateException: The frame is displayable. at java.desktop/java.awt.Frame.setUndecorated(Frame.java:926) at com.ggl.testing.SnakeGame$GameFrame.<init>(SnakeGame.java:41) at com.ggl.testing.SnakeGame.main(SnakeGame.java:24) Oracle has a helpful tutorial, Creating a GUI With Swing. Skip the Learning Swing with the NetBeans IDE section. Pay … Read more

Start AlarmManager if device is rebooted

Create Boot Receiver using following code : public class BootBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context pContext, Intent intent) { if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){ // Do your work related to alarm manager } } } In your Manifest, register this Broadcast receiver : <receiver android:name=”com.yourapp.BootBroadcastReceiver” android:enabled=”true” > <intent-filter> <action android:name=”android.intent.action.BOOT_COMPLETED” /> </intent-filter> </receiver> And don’t forget to … Read more

How to restart service after the app is killed from recent tasks

Override onTaskRemoved() in your service and use alarm manager to start the service again. Below is code from our app that does the same and works fine: @Override public void onTaskRemoved(Intent rootIntent) { super.onTaskRemoved(rootIntent); Log.d(TAG, “TASK REMOVED”); PendingIntent service = PendingIntent.getService( getApplicationContext(), 1001, new Intent(getApplicationContext(), MyService.class), PendingIntent.FLAG_ONE_SHOT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 1000, service); … Read more

Android AlarmManager after reboot

I’m not sure if I understand the boot receiver and how to then restart all the alarms. Just call your code to call setRepeating() (or whatever) on AlarmManager. For example, in this sample project, PollReceiver is set to receive BOOT_COMPLETED. In onReceive(), it reschedules the alarms: package com.commonsware.android.schedsvc; import android.app.AlarmManager; import android.app.PendingIntent; import android.content.BroadcastReceiver; import … Read more

android:configChanges=”orientation” does not work with fragments

Based on my experience with Honeycomb 3.0 and compatibility library (r1). configChange=”orientation” does work with fragments with respect to preventing the activity (to which it is applied) being re-created on an orientation change. If you want the fragment not to be re-created on activity re-creation then call setRetainInstance in onCreate. Unless I’m missing something I … Read more

How to restart app if it unexpectedly shutdown

As far as I know, some sort of apps can be run in background and can be restarted in specific case. This is from Apple docs https://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/doc/uid/TP40007125 If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives. In such a … Read more

How do I shutdown, restart, or log off Windows via a bat file?

The most common ways to use the shutdown command are: shutdown -s — Shuts down. shutdown -r — Restarts. shutdown -l — Logs off. shutdown -h — Hibernates. Note: There is a common pitfall wherein users think -h means “help” (which it does for every other command-line program… except shutdown.exe, where it means “hibernate”). They … Read more