Monday, May 30, 2011

Android Progress Dialog Example

In situations when you need to wait some operation it is good practice to notify user that operation is in progress.For this cases in Android present several classes which can help with this. One of them I am going to demonstrate.

In this tutorial, I will show you how to add a progress dialog to your Android application. A dialog is usually a small window or tab that appears before any activity in your application. It is intended to display alerts or information to the user. A progress dialog can be used to either show some processing activity to the user or to show the progress of some custom activity using the progress bar.

To create a Progress Dialog, we can make use of the ProgressDialog class which is an extension of the AlertDialog class. It can be used to display a standard progress dialog with a spinning wheel and some custom text. You can display your Progress Dialog using a simple show () call on your dialog object.

Here's the syntax to create a standard Progress dialog:
ProgressDialog MyDialog = ProgressDialog.show( MyActivity.this, "TITLE " , " Loading. Please wait ... ", true);
It has four parameters:
1. The application context
2. The title of the Dialog
3. The Dialog Text or Message which is displayed in the dialog
4. A boolean value indicating whether the progress is indeterminate

and to disapper the ProgressDialog you have to add dismiss() like this:
MyDialog.dismiss();

Now I will show how to use ProgressDialog class for showing progress dialog. I will show how to create progress dialog with title and without title.

With TItle: ProgressDialog.show(Main.this, "In progress", "Loading");


What if I you want to hide the title? just put empty string as title parameter.
ProgressDialog.show(Main.this, "", "Loading...");

Example:

import android.app.ProgressDialog;
//in the class...
private ProgressDialog progressBar;

//when you want the dialog to show the first time.
progressBar = ProgressDialog.show(Main.this, "Disconnecting", "Please wait for few secs...");

//when you want the progressbar to disappear
if (progressBar.isShowing()) {
progressBar.dismiss();
}

Friday, May 27, 2011

Error: Unable to open class file R.java and How to fix it.





[2011-05-27 12:12:39 - listActivity] ERROR: Unable to open class file /root/workspace/Manifest.java: No such file or directory

[2011-05-27 13:50:38 - listActivity] ERROR: Unable to open class file /root/workspace//R.java: No such file or directory




R.java and Manifest.java is a automatically generated file.


The ADT has a few such annoying bugs. But you can sort them out..
What usually helps is:



1. Close Project->Open Project > Build Automatically .
2.Another thing that sometimes helps is right click project > android tools > fix project properties and remove unnecessary content or jar files.

3.Or you can do Project->clean and Refresh .




If still it not generating R.java files then check your class there must be a extra line..

Import R.java.*; Remove that and then do all the above one by one..

Hope it help ..

If someone know other way please let me know.

Thanks

 

Tuesday, May 24, 2011

Conversion to Dalvik format failed with error 1

Sometime You will encounter this problem when trying to Build Android Project on Eclipse..
 You will get such output in console:



[2011-05-24 09:25:03 - Android C2DM] Dx 1 error; aborting
[2011-05-24 09:25:03 - Android C2DM] Conversion to Dalvik format failed with error 1


You can solve this problem:


Go to Project » Properties » Java Build Path » Libraries and remove all except the "Android X.Y" (in my case Android 2.2). click OK. 
and then
Go to Project » Clean » Clean projects selected below » select your project and click OK.


 That work for me. Hope it works for you too.!!!!

How TOPT Works: Generating OTPs Without Internet Connection

Introduction Have you ever wondered how authentication apps like RSA Authenticator generate One-Time Passwords (OTPs) without requiring an i...