android - Android 小部件有任何 "onCreate"方法吗?

标签 android android-widget

我正在关注this将 EULA 添加到我的 Android 应用程序的教程,但我有两个问题: 1) 我的应用程序基于小部件,我想在小部件启动后立即显示我的 EULA。小部件有“onCreate”方法吗? 2)如果用户拒绝EULA,我想关闭我的应用程序。我是 C# 程序员,所以我不知道 Android 应用程序是否有“Exit()”方法。如何在没有用户操作的情况下强制关闭我的应用程序?

最佳答案

根据android doc page for AppWidget ,您可能对 onEnabled 感兴趣和 onDisabled方法:

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)

关于android - Android 小部件有任何 "onCreate"方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7326508/

相关文章:

android - 垂直 DrawerLayout 或 SlidingPaneLayout

android - 如何在 CursorAdapter 中使用 2 个游标?

Java 将多维数组传递给 PHP

java - adapter.add(event) 抛出 java.lang.UnsupportedOperationException

java - 如何使用 Retrofit 为所有请求定义一个 Header?

java - 如何有效地更新应用程序小部件

android - 如何在 RatingBar 中设置星星的自定义大小

android - Lombok 不工作 Android Studio 3.0

java - Android map 应用程序未在 Eclipse 上运行

android - 如何使 View 对点击使用react