2011-09-06 37 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(上下文)

相关问题