jueves, 28 de noviembre de 2013

Cast from Object to Integer


Problem:

I need to cast from Object to Int.

Solution:

If you're sure that this object is an Integer :
int i = (Integer) object;
Or, starting from Java 7, you can equivalently write:
int i = (int) object;
Beware, it can throw a ClassCastException if your object isn't an Integer and aNullPointerException if your object is null.

lunes, 7 de octubre de 2013

How to Install Android on Notebook or computer

how run android on pc
The success of Android mobile platform Android is much more than a million active applications, there is a small span. Android powers millions of phones, tablets and netbooks and desktops now. Yes, you heard me right.
How to run Android on a computer
You can also run Android on your netbook or desktop. In this post, I'll let you run Android on your laptop or netbook.

Things you need

Before you start reading this tutorial, make sure you gather all the necessary items.

  •       A USB drive or pen drive with 256 MB + Space. (Or CD)
  •       A custom netbook or desktop (click here)
  •       Some of the basic computing skills
  •       And of course - this guide

How to Install Android on a computer or Notebook

Follow the step to step guide for installing Android on your device. It may take up to 30 minutes for installation.
Preparing USB drive
Step 1: Format your USB drive to back up your important data first.

Step 2: Now go to this link http://www.android-x86.org/download and find your device is compatible with the Android version. Once you click on View and download to find out.

Step 3: Now that Android-x86 download, and on the other hand be able to download UNetbootin, click here to download. The software to USB drive. Iso will help you unpack and a bootable device.

Step 4: Once you get to download two files, open UNetbootin. Diskimage tick button.
how to instal android on pc
Now down list, select from the ISO. Android-X85 file by clicking the Browse ... 'Button. Now the rest of the settings and click OK.
run android apps on windows pc free download
How to run Android on a computer

Now let UNetbootin USB drive you want to download files. Once the file you want to run in the same android device, reboot, or load end. If you want to run, then out of the other android device.
Note: If you wish, you can burn the CD on the android-x86 iso.
How to run Android Apps on your Windows pc using a free software

 Installing Android on a computer

Now that you've made ​​USB or CD, the next step is to install on your computer or laptop, or netbook.

Step 1: Plug your Android and then reboots the system you want to install the device in your USB.

Step 2: Start up, you computer will ask you to boot the device. Select your USB drive for booting.

(Some computers, you can choose to boot from USB on your computer, the boot process will need to press the F2 or F10 key)

When you boot the computer USB discharge starts, it shows the installation setting.

Step 3: Select the Live CD - the installation without running the Android-x86. From the selection of the installation.
 Android phone to your PC
 Step 4: Wait for few minutes, The Setup will boot Android. After few minutes, You'll see Android Desktop.


 How To Run Android Apps on Your Windows PC

lunes, 4 de febrero de 2013

Converting from Editable to int in android


How to converting from Editable to int in android


Problem:

Need to convert from Editable to int

Solution:

Integer.ParseInteger(R2.getText())

Source: stackoverflow

Prompt User Input with an AlertDialog


How to prompt User Input with an AlertDialog


Problem:

Need to ask you some information to user using an Alert Dialog:

Solution:

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Title");
alert.setMessage("Message");
// Set an EditText view to get user input 
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
  String value = input.getText();
  // Do something with value!
  }
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
  }
});

alert.show();

Source: Android Snippets


viernes, 16 de noviembre de 2012

Data Storage - Using Shared Preferences




Using Shared Preferences


The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).
To get a SharedPreferences object for your application, use one of two methods:
  • getSharedPreferences() - Use this if you need multiple preferences files identified by name, which you specify with the first parameter.
  • getPreferences() - Use this if you need only one preferences file for your Activity. Because this will be the only preferences file for your Activity, you don't supply a name.
To write values:
  1. Call edit() to get a SharedPreferences.Editor.
  2. Add values with methods such as putBoolean() andputString().
  3. Commit the new values with commit()
To read values, use SharedPreferences methods such as getBoolean() and getString().
Here is an example that saves a preference for silent keypress mode in a calculator:
public class Calc extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile";

    @Override
    protected void onCreate(Bundle state){
       super.onCreate(state);
       . . .

       // Restore preferences
       SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
       boolean silent = settings.getBoolean("silentMode", false);
       setSilent(silent);
    }

    @Override
    protected void onStop(){
       super.onStop();

      // We need an Editor object to make preference changes.
      // All objects are from android.context.Context
      SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
      SharedPreferences.Editor editor = settings.edit();
      editor.putBoolean("silentMode", mSilentMode);

      // Commit the edits!
      editor.commit();
    }
}

source: Android.developer

sábado, 10 de noviembre de 2012

How to pass data from activity to service




Pass data from activity to service
In activity:
?
1
2
3
4
5
6
7
8
Intent myIntent = new Intent(MainActivity.this, MyService.class);
    
Bundle bundle = new Bundle();
bundle.putCharSequence("extraData", data);
myIntent.putExtras(bundle);
    
pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0);
Basically, it's similar to that in "Pass data between activity".

In service side, there are no getIntent().getExtras() in Service class. We can handle it in onStart() call-back method, intent will be passed as parameter.
?
1
2
3
4
5
6
7
8
9
10
public void onStart(Intent intent, int startId) {
 // TODO Auto-generated method stub
 super.onStart(intent, startId);
  
 Bundle bundle = intent.getExtras();
 data = (String) bundle.getCharSequence("extraData");
 smsTextToSend = (String) bundle.getCharSequence("extraSmsText");
 ...
}