BasicActivity.java :  » Widget » my-daily-phrases » com » googlecode » mydailyphrases » activity » Android Open Source

Android Open Source » Widget » my daily phrases 
my daily phrases » com » googlecode » mydailyphrases » activity » BasicActivity.java
package com.googlecode.mydailyphrases.activity;

import com.googlecode.mydailyphrases.Database;

import android.app.Activity;
import android.app.AlertDialog;
import android.appwidget.AppWidgetManager;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;

public class BasicActivity extends Activity {

    protected Database mDatabase;

    public BasicActivity() {
    }
    
    //TODO: check lifecycle: how should we manage database connection?
    
    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(mDatabase != null) {
            mDatabase.close();
        }
    }

    protected void showAlertAndFinish(String message) {
        new AlertDialog.Builder(this)
            .setMessage(message)
            .setCancelable(false)
            .setPositiveButton("OK", new OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    BasicActivity.this.finish();
                }
            }).show();
    }

    protected void broadcastWidgetUpdate(int appWidgetId) {
        Intent update = new Intent();
        update.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, new int[] { appWidgetId });
        update.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
        sendBroadcast(update);
    }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.