Reputation: 2956
I'm following this tutorial for adding EULA to my Android application, but i have two problems: 1) My app is based on widget and i would like to show my EULA as soon as widget is started. Is there any "onCreate" method for widgets? 2) If user refuse EULA, i would like to close my app. I'm C# programmer, so i don't know if there's any "Exit()" method for Android apps. How to forcefully close my app without user's action?
Upvotes: 3
Views: 5071
Reputation: 7024
There isn't an onCreate()
per se, but there is a way to show an activity when your widget is first added. One way of doing this is the following.
In your AppWidget provider XML file be sure to add as a property of appwidget-provider
:
android:configure="your.eula.activity"
and don't forget to declare your.eula.activity
in your AndroidManifest.xml
<activity android:name="your.eula.activity">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
And in your.eula.activity
's onCreate()
you should call
setResult(RESULT_CANCELED);
finish();
Upvotes: 1
Reputation: 49410
According to the android doc page for AppWidget, you may be interested in the onEnabled and onDisabled methods:
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.
So, if the user refuses, you can call onDisabled(Context)
Upvotes: 5
Reputation: 13252
Can't you just show the EULA when you do your initialization and so forth? I'm not familiar with your code, so I'm not sure if it's possible in your case, but it's a possibility.
To end an activity, simply call this.finish()
.
Upvotes: 0