2011-09-06 62 views
2

我下面this教程添加EULA我的Android應用程序,但我有兩個問題: 1)我的應用程序是基於小窗口,我想盡快窗口小部件開始顯示我的EULA。小部件是否有任何「onCreate」方法? 2)如果用戶拒絕EULA,我想關閉我的應用程序。我是C#程序員,所以我不知道是否有任何Android應用程序的「Exit()」方法。如何在沒有用戶操作的情況下強制關閉我的應用程序?有沒有Android小部件的「onCreate」方法?

回答

1

沒有一個onCreate()本身,但是有一種方法可以在您的小部件首次添加時顯示活動。做這件事的一種方法如下。

在你AppWidget提供商XML文件一定要加爲appwidget-provider屬性:

android:configure="your.eula.activity" 

,不要忘了在你的AndroidManifest.xml

<activity android:name="your.eula.activity"> 
    <intent-filter> 
      <action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" /> 
    </intent-filter> 
</activity> 

而且在your.eula.activity的申報your.eula.activityonCreate()您應該致電

setResult(RESULT_CANCELED); 
finish(); 
+0

都不行 - 伊拉類是不活動的,它只是一個類:) – guest86

+0

@ guess86:你爲什麼不能做出伊拉類的活動嗎? – ccheneson

+0

是的,我現在正在處理它,然後我會嘗試從郵編上面的代碼 – guest86

0

你就不能顯示EULA,當你做你的初始化等等?我不熟悉你的代碼,所以我不確定你的情況是否可能,但這是可能的。

要結束的活動,只需撥打this.finish()

+0

不只是活動 - 整個應用程序!如何實現這一目標? – guest86

+0

我真的不認爲這是建議這樣做。但做下面的工作應該:android.os.Process.killProcess(android.os.Process.myPid()); –

+0

爲什麼你需要真正殺死這個過程?如果有人想要,他們可以拒絕您的EULA,然後在您的應用程序中手動啓動任何活動。您*可以*將EULA接受狀態寫入'SharedPreferences',並在您的應用程序的所有活動和組件中爲該標誌設置警戒。即使這可以被規避,對我來說似乎沒什麼用處。 –

4

按照android doc page for AppWidget,你可能有興趣在onEnabledonDisabled方法:

onEnabled(Context) 
This is called when an instance the App Widget is created for the first time. 
For example, if the user adds two instances of your App Widget, this is only called the first time. 
If you need to open a new database or perform other setup that only needs to occur once for all App Widget instances, then this is a good place to do it. 

onDisabled(Context) 
This is called when the last instance of your App Widget is deleted from the App Widget host. 
This is where you should clean up any work done in onEnabled(Context), such as delete a temporary database. 

所以,如果用戶拒絕,你可以調用onDisabled(上下文)

相關問題