请不要因为一个菜鸟问题而用鱼叉攻击我。
我正在使用 SL4A 开发一个 android 应用程序,当我的应用程序启动时,它在脚本执行时在后台运行。我不确定从哪里开始,但每次单击我的图标时,它都会重新启动我的应用程序。我尝试过使用不同的启动模式,但没有发生任何不同。我认为这与 OnCreate 代码和通知的设置有关。我需要帮助保存我的应用程序状态,然后在重新单击图标或单击通知栏时恢复。我已经尝试了一切,不得不转向这里寻求帮助。无论如何,我都不是 android 编程的专家。谢谢大家,温柔点;)
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;
}