Monday, March 26, 2012

SimpleDateFormat


SimpleDateFormat

Usage of SimpleDateFormat:

?
1
2
3
SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy  hh:mm:ss a"); 
String now = formatter.format(new Date());

Final Android 3.0 Platform and Updated SDK Tools


Final Android 3.0 Platform and Updated SDK Tools


We are pleased to announce that the full SDK for Android 3.0 is now available to developers. The APIs are final, and you can now develop apps targeting this new platform and publish them to Android Market. The new API level is 11.
For an overview of the new user and developer features, see theAndroid 3.0 Platform Highlights.
Together with the new platform, we are releasing updates to our SDK Tools (r10) and ADT Plugin for Eclipse (10.0.0). Key features include:
  • UI Builder improvements in the ADT Plugin:
    • New Palette with categories and rendering previews. (details)
    • More accurate rendering of layouts to more faithfully reflect how the layout will look on devices, including rendering status and title bars to more accurately reflect screen space actually available to applications.
    • Selection-sensitive action bars to manipulate View properties.
    • Zoom improvements (fit to view, persistent scale, keyboard access) (details).
    • Improved support for layouts, as well as layouts with gesture overlays.
  • Traceview integration for easier profiling from ADT. (details)
  • Tools for using the Renderscript graphics engine: the SDK tools now compiles .rs files into Java Programming Language files and native bytecode.
To get started developing or testing applications on Android 3.0, visit the Android Developers site for information about the Android 3.0 platform, the SDK Tools, and the ADT Plugin.

How to pass bitmap between activities


How to pass bitmap between activities

A bitmap created from R.drawable.icon will be passed from one activity (AndroidPassingBitmap) to another activity (AndroidReceiveBitmap).

How to passing bitmap between activities

Modify the activity AndroidPassingBitmap.java, simple create a bitmap and pass to the second activity.
/AndroidPassingBitmap/src/com/AndroidPassingBitmap/AndroidPassingBitmap.java
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.AndroidPassingBitmap;
 
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
 
public class AndroidPassingBitmap extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
 
        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
         
        Intent intent = new Intent();
        intent.setClass(AndroidPassingBitmap.this, AndroidReceiveBitmap.class);
        intent.putExtra("Bitmap", bitmap);
        startActivity(intent);
 
    }
}


Create a new activity to retrieve and display the bitmap.
/workspace/AndroidPassingBitmap/src/com/AndroidPassingBitmap/AndroidReceiveBitmap.java
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.AndroidPassingBitmap;
 
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.widget.ImageView;
 
public class AndroidReceiveBitmap extends Activity {
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
   
  Bitmap bitmap = (Bitmap)this.getIntent().getParcelableExtra("Bitmap");
   
  setContentView(R.layout.newimage);
  ImageView viewBitmap = (ImageView)findViewById(R.id.bitmapview);
   
  viewBitmap.setImageBitmap(bitmap);
   
 }
 
}


Create the layout of the second activity.
/workspace/AndroidPassingBitmap/res/layout/newimage.xml
?
1
2
3
4
5
6
7
8
9
10
11
12
13
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<ImageView 
    android:id="@+id/bitmapview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
</LinearLayout>


Update AndroidManifest.xml to include the second activity in the package.
/workspace/AndroidPassingBitmap/AndroidManifest.xml
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="utf-8"?>
      package="com.AndroidPassingBitmap"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".AndroidPassingBitmap"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".AndroidReceiveBitmap"
                  android:label="AndroidReceiveBitmap">
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="4" />
 
</manifest>