2

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?

guest86
  • 2,894
  • 8
  • 49
  • 72

3 Answers3

5

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)

ccheneson
  • 49,072
  • 8
  • 63
  • 68
1

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();
Jon Willis
  • 6,993
  • 4
  • 43
  • 51
0

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().

Michell Bak
  • 13,182
  • 11
  • 64
  • 121
  • Not just activity - WHOLE app! How to achieve that? – guest86 Sep 06 '11 at 22:08
  • I don't really think it's recommended to do that. But doing the following should work: android.os.Process.killProcess(android.os.Process.myPid()); – Michell Bak Sep 06 '11 at 22:14
  • Why would you need to actually kill the process? If someone wants to, they can decline your EULA, and then manually launch any activity in your app. You *could* write EULA accept status to `SharedPreferences` and have a guard in all activities and components in your app for that flag. Even that can be circumvented and to me seems to serve little purpose. – Jon Willis Sep 06 '11 at 22:23
  • Well, is there any way to FORCE user to choose: accept EULA and use program, or refuse eula and not be able to use it unless he/she accept it? – guest86 Sep 06 '11 at 22:30