android - how to use Alert Box? -


i have application uses data stored on sd card, problem, want display dialog box error message before application terminates. tried create dialog box not in activity in simple class. code use unkown. first part , second every thing ok. when sd card installed , when use nexus google tablet. have message no sdcard before application crashed, or start other activity used tell user application need sdcard. code use given below. application print log crash when no sdcard.

public file getrootdirectory()    {         if (this.rootdirectory == null)         {             file sdcardroot = mainapplication.getinstance().getsdcardrootdirectory();             if (sdcardroot != null)             {                 this.rootdirectory = sdcardroot;             }             else if(build.brand.equals("google"))             {                 this.rootdirectory = environment.getexternalstoragepublicdirectory(mainapplication.appli_directory);             } else {                 log.d(class_tag, " no  carte sd ");                   /**                  * trying start fail activity                   */                 //intent intent = new intent(context, failactivity.class)                 //.setflags(intent.flag_activity_new_task);                   //context.startactivity(intent);               }             log.i(class_tag, "root directory set :" + this.rootdirectory.getabsolutepath());         }         return this.rootdirectory;     } 

try

  boolean issdpresent = android.os.environment.getexternalstoragestate().equals(android.os.environment.media_mounted);      if(!issdpresent)     {       // yes sd-card present       alertdialog.builder builder = new alertdialog.builder(getactivity());             builder.setmessage("sorry,sd card not found")                    .setpositivebutton(r.string.fire, new dialoginterface.onclicklistener() {                        public void onclick(dialoginterface dialog, int id) {                        finish();                        }                    });             builder.setcancelable(false);                    // create alertdialog object , return             builder.create();             builder.show();       } 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -