Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

public class Main {
    public static void displayError(String message, final Class<?> activity, final Context context) {
        // no deals found so display a popup and return to search options
        AlertDialog.Builder builder = new AlertDialog.Builder(context);

        // set title
        builder.setTitle("No Results");

        // set dialog message
        builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                        Intent i = new Intent(context, activity);
                        ((Activity) (context)).finish();
                        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
                        context.startActivity(i);
                    }
                });
        // create alert dialog
        AlertDialog alertDialog = builder.create();

        // show it
        alertDialog.show();
    }
}