Search This Blog

Showing posts with label Android Programming. Show all posts
Showing posts with label Android Programming. Show all posts

Thursday, 14 June 2012

Basic About Android Intents



Basics about the Intents

Intents are asynchronous messages which allow Android application components to request functions from other components of same or other applications in android system.


An Activity can use Intent Messaging to send the start-up data to another activity.

The loosely coupled application components connect together using Intents.

Intents are instances of the android.content.Intent class.

There are two type of intents in android

1.2. Explicit Intents

Explicit Intents specify the name of the component need to call by its java class identifier.

Example :

Intent I = new Intent(this,NextActivity.class);
startActivity(I);

Explicit Intents will used with in the applications.

1.3. Implicit Intents

Implicit Intents specify the action to perform and the URI which is used by action

Example :

Intent I = new Intent(Intent.ACTION_VIEW,Uri.parse("http://creativeandroidapps.blogspot.in");

Implicit Intents are send to the Android system to searches for all components which are registered for the specific action and the data type. If only one component found then system start that component otherwise a dialog is prompted for user selection.


Tuesday, 12 June 2012

3 things which should not change after publish


3 Things which should not change after publish

1) Application package name could not be change after publish of an application. Changing an application package name will recognize the application as a new application. On device the application will not update and install as new application.

2) Application signature could not be change after publish of an application. Changing the signature will recognize a different author of the application and fail the update of the application on device.

3) The activity name specified by android: name should not change. Changing the name could lead surprise issues with application on device. For Example the shortcut of the application will not work. Activity name is a public property and other applications and linking are done with this name.

Thursday, 7 June 2012

Quick Layout Tutorial for Android - Linear layout


Linear Layout

Linear Layout place the controls in one line either horizontal or vertical. The direction will be specified by android:orientation attribute.

For Example :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="horizontal"
 android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <Button 
     android:id="@+id/welcomebutton"
     android:text="Welcome"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
    <TextView
     android:text="CreativeAndroidApps"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content" />
</LinearLayout>
 
see the below screen shot
 
Linear Layout
 
See here how to create the LinearLayout in code 
 
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
LinearLayout ll;
ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
TextView tv = new TextView(this);
tv.setText(" CreativeAndroidApps");
Button bv = new Button(this);
bv.setText("Welcome");
ll.addView(tv);
ll.addView(bv);
 
} 

to change the orientation to vertical use LinearLayout.VERTICAL in setOrientation 
method
 
The forms are normally created using linear layouts. 
 
 
 





Quick Layout Tutorial for Android - Frame layout

Frame Layout

Frame Layout display one control at a time. Frame layout is used to create the layers of components. All the components positions are calculated from the top left of the screen.

The components overlapping will display overlapped.

For Example :


<FrameLayout 
 android:layout_width="fill_parent" 
 android:layout_height="fill_parent" 
 xmlns:android="http://schemas.android.com/apk/res/android">
 <ImageView 
  android:src="@drawable/logo"
  android:scaleType="fitCenter"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"/>
 <TextView
  android:text="CreativeAndroidApps"
  android:textSize="16sp"
  android:textColor="#000000"
  android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:gravity="center"/>
</FrameLayout>

See the below screen shot for XML

Frame Layout






















To hide and show the components at run time the Frame Layout could be use by specify the visibility of the component.
In XML the android:visibility could be define to visible,invisible (take show but not visible),gone (not visible and not take any space).

setVisibility function will be used code fro same purpose.

See below how to use the Frame layouts in programming


 public void onCreate(Bundle savedInstanceState) {   
   super.onCreate(savedInstanceState);   
   ImageView iv = new ImageView(this);   
   iv.setImageResource(R.drawable.logo);   
   iv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));   
   iv.setScaleType(ScaleType.FIT_CENTER);   
   TextView tv = new TextView(this);
   tv.setText("CreativeAndroidApps");   
   tv.setTextSize(16);   
   tv.setGravity(Gravity.CENTER);
   tv.setTextColor(Color.BLACK);     
   FrameLayout fl = new FrameLayout(this);   
   fl.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));   
   fl.addView(iv);   
   fl.addView(tv);   
   setContentView(fl);   
 }