Android - Resuming application state - SL4A
- by toyotajon93
please dont harpoon me for a noob-ish question.
I am working on an android application using SL4A, when my application starts it runs in the background while the script is being executed. I'm not sure where to start but each time I click my icon, it re-starts my application. I have tried using different launchmodes with nothing different happening. I'm thinking it has to do with the OnCreate code, and the setting of the notification. I need help saving my application state and then resuming on either re-click of icon or click from notification bar. I've tried everything had to turn here for help. I am not a pro at android programming by any means. Thanks guys, be gentle ;)
Public void onCreate() {
super.onCreate();
mInterpreterConfiguration = ((BaseApplication) getApplication())
.getInterpreterConfiguration();
}
@Override
public void onStart(Intent intent, final int startId) {
super.onStart(intent, startId);
String fileName = Script.getFileName(this);
Interpreter interpreter = mInterpreterConfiguration
.getInterpreterForScript(fileName);
if (interpreter == null || !interpreter.isInstalled()) {
mLatch.countDown();
if (FeaturedInterpreters.isSupported(fileName)) {
Intent i = new Intent(this, DialogActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.putExtra(Constants.EXTRA_SCRIPT_PATH, fileName);
startActivity(i);
} else {
Log
.e(this, "Cannot find an interpreter for script "
+ fileName);
}
stopSelf(startId);
return;
}
// Copies script to internal memory.
fileName = InterpreterUtils.getInterpreterRoot(this).getAbsolutePath()
+ "/" + fileName;
File script = new File(fileName);
// TODO(raaar): Check size here!
if (!script.exists()) {
script = FileUtils.copyFromStream(fileName, getResources()
.openRawResource(Script.ID));
}
copyResourcesToLocal(); // Copy all resources
if (Script.getFileExtension(this)
.equals(HtmlInterpreter.HTML_EXTENSION)) {
HtmlActivityTask htmlTask = ScriptLauncher.launchHtmlScript(script,
this, intent, mInterpreterConfiguration);
mFacadeManager = htmlTask.getRpcReceiverManager();
mLatch.countDown();
stopSelf(startId);
} else {
mProxy = new AndroidProxy(this, null, true);
mProxy.startLocal();
mLatch.countDown();
ScriptLauncher.launchScript(script, mInterpreterConfiguration,
mProxy, new Runnable() {
@Override
public void run() {
mProxy.shutdown();
stopSelf(startId);
}
});
}
}
RpcReceiverManager getRpcReceiverManager() throws InterruptedException {
mLatch.await();
if (mFacadeManager==null) { // Facade manage may not be available on startup.
mFacadeManager = mProxy.getRpcReceiverManagerFactory()
.getRpcReceiverManagers().get(0);
}
return mFacadeManager;
}
@Override
protected Notification createNotification() {
Notification notification =
new Notification(R.drawable.script_logo_48, this.getString(R.string.loading), System.currentTimeMillis());
// This contentIntent is a noop.
PendingIntent contentIntent = PendingIntent.getService(this, 0, new Intent(), 0);
notification.setLatestEventInfo(this, this.getString(R.string.app_name), this.getString(R.string.loading), contentIntent);
notification.flags = Notification.FLAG_ONGOING_EVENT;
return notification;
}