Demo:
1)ImplicitIntents Activity:
package com.venkool;
1)ImplicitIntents Activity:
package com.venkool;
import
android.app.Activity;
import
android.content.Intent;
import
android.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
public class
ImplicitIntentsDemoActivity extends Activity {
/** Called when the activity is first
created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first);
Button btnClick = (Button)
findViewById(R.id.btnClick);
btnClick.setOnClickListener(new
OnClickListener() {
@Override
public void onClick(View v)
{
// TODO
Auto-generated method stub
Intent intent = new Intent();
intent.setAction("action1");
intent.addCategory("category1");
startActivity(intent);
}
});
}
}
2)SecondScreen Activity:
package com.venkool;
import
android.app.Activity;
import
android.os.Bundle;
public class SecondScreen extends Activity {
/** Called when the activity is first
created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
}
}
3)first.xml:
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@color/FirstBackground">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Implicit
Intents Demo"
android:textSize="20dp"
android:textStyle="bold"
/>
<Button
android:id="@+id/btnClick"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center"
android:text="Click"
/>
</LinearLayout>
4)second.xml:
<?xml version="1.0"
encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/SecondBackground"
android:orientation="vertical"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:gravity="center"
android:text="Second
Screen"
android:textSize="30dp"
android:textStyle="bold"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Implicit
Intents"
android:textSize="20dp"
android:textStyle="bold"
/>
</LinearLayout>
5)Add this code into manifest.xml:
<activity
android:label="Second
Screen"
android:name=".SecondScreen"
>
<intent-filter >
<action android:name="action1"
/>
<category android:name="category1"
/>
<category android:name="android.intent.category.DEFAULT/>
</intent-filter>
</activity>
6)Download this Project Click Here
No comments:
Post a Comment