請不要在我的noob-ish問題中使用魚叉。Android - 正在恢復應用程序狀態 - SL4A
我正在使用SL4A的Android應用程序,當我的應用程序啓動時,它在腳本執行時在後臺運行。我不確定從哪裏開始,但每次點擊我的圖標時,都會重新啓動我的應用程序。我嘗試過使用不同的launchmode,但沒有發生任何不同的事情。我認爲它與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;
}
這將與薑餅工作? – toyotajon93
@ toyotajon93是的,爲什麼不呢? – LuxuryMode