I made an app whose goal is to show some information it gets from server via HTTP GET each second. It runs in fullscreen and stays awake. Some kind of information board. It works fine on phones and tablets, but I need it to work on Minix Neo X7/8. On Minix it just spontaneously goes to background after a couple of minutes and works for a while in background after that system kills it.
How to make it work on Minix? I have no idea why this kind of magic happens.
--- Update --- This is the complete source of the app.
public class MainActivity extends Activity
{
private final String URL = "http://192.168.1.5:8080";
private final String SOUND_FILE_NAME = "file:///mnt/usb_storage/USB_DISK0/udisk0/events/sound.mp3";
//--------------------------------------------------------------------
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
createScene();
startPolling();
}
//--------------------------------------------------------------------
private void createScene()
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.main);
WebView view = (WebView) findViewById(R.id.MainWebView);
view.setWebChromeClient(new WebChromeClient());
view.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode,
String description,
String failingUrl)
{
new Timer().schedule(new TimerTask() {
@Override
public void run() {
WebView view = (WebView) findViewById(R.id.MainWebView);
view.loadUrl(URL);
}
}, 5000);
super.onReceivedError(view, errorCode, description, failingUrl);
}
});
view.clearCache(true);
view.clearHistory();
view.getSettings().setJavaScriptEnabled(true);
view.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
view.loadUrl(URL);
}
//--------------------------------------------------------------------
private void startPolling()
{
_http_client = new DefaultHttpClient();
_timer = new Timer();
_timer.schedule(new TimerTask() {
@Override
public void run() {
try {
HttpResponse response = _http_client.execute(new HttpGet(URL + "/info"));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
String payload = out.toString();
out.close();
Log.d("GK", "got payload " + payload);
String data = "{\"data\":" + payload + "}";
Log.d("GK", "parsing " + data);
JSONObject json = new JSONObject(data);
JSONArray info = json.getJSONArray("data");
final int maxInfo = 3;
if (info.length() > maxInfo) {
File f = new File(Uri.parse(SOUND_FILE_NAME).getPath());
if (f.exists() && !f.isDirectory()) {
startAudio(SOUND_FILE_NAME);
}
} else {
stopAudio();
}
} else {
stopAudio();
//Closes the connection.
response.getEntity().getContent().close();
}
} catch (Exception e) {
stopAudio();
}
}
}, 0, 1000);
}
//--------------------------------------------------------------------
private Boolean isPlaying() { return _player != null && _player.isPlaying(); }
//--------------------------------------------------------------------
private void startAudio(String audioUri)
{
if (!isPlaying())
{
_player = MediaPlayer.create(this, Uri.parse(audioUri));
_player.setOnCompletionListener(new musicCompletionListener());
_player.start();
}
}
//--------------------------------------------------------------------
private void stopAudio()
{
if (isPlaying()) { _player.stop(); }
}
//////////////////////////////////////////////////////////////////////
// classes
//--------------------------------------------------------------------
private class musicCompletionListener implements MediaPlayer.OnCompletionListener
{
public void onCompletion(MediaPlayer player)
{
if (_player != null)
{
_player.release();
_player = null;
}
}
}
private MediaPlayer _player;
private HttpClient _http_client;
private Timer _timer;
}
Thanx in advance.