我正在按照这个教程(链接)为我的Android应用添加 EULA,但是我有两个问题:
1) 我的应用程序基于小部件,我想在小部件启动时立即显示我的EULA。 小部件是否有“ onCreate”方法?
2) 如果用户拒绝 EULA,则我想关闭我的应用程序。 我是C#程序员,因此不知道Android应用程序是否有“ Exit()”方法。 如何在没有用户操作的情况下强制关闭我的应用程序?
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(Context)函数。
没有一个明确的onCreate()
方法,但是有一种方法可以在小部件首次添加时显示一个活动。一种做法如下:
在你的AppWidget提供程序XML文件中,确保将其作为appwidget-provider
的属性添加:
android:configure="your.eula.activity"
不要忘记在你的AndroidManifest.xml
中声明your.eula.activity
<activity android:name="your.eula.activity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
your.eula.activity
。 setResult(RESULT_CANCELED);
finish();
你不能在初始化和其他操作时显示最终用户许可协议吗?我对你的代码不熟悉,所以不确定在你的情况下是否可能,但这是一个可能性。
要结束一个活动,只需调用this.finish()
。
SharedPreferences
,并在你应用的所有活动和组件中设置一个守卫标志。即使如此,这也可以被规避,对我来说似乎没有什么实际意义。 - undefined