Android Intent Example
Definition : To understand Activity, Intent
Create sample application with login module.(Check username and password)
On successful login, go to next screen. And on failing login, alert user using Toast. Also pass username to next screen.
File Name : E2Activity.java
package bsr.e2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class E2Activity extends Activity {
/** @author Bipin S Rupadiya , www.gtu-android.blogspot.com
*
* 2) To understand Activity, Intent
* a. Create sample application with login module.(Check username and password)
* b. On successful login, go to next screen. And on failing login, alert user using Toast.
* c. Also pass username to next screen.
**/
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//create an intent
final Intent intent=new Intent(this,Screen2.class);
//login event
final Button btnLogin = (Button)findViewById(R.id.cmdLogin);
btnLogin.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
EditText fldu=(EditText)findViewById(R.id.txtusr);
EditText fldp=(EditText)findViewById(R.id.txtPwd);
String un= fldu.getText().toString();
if((fldu.getText().toString().equals("bipin"))&&(fldp.getText().toString().equals("rupadiya")))
{
intent.putExtra("uname", fldu.getText().toString());
startActivity(intent);
}
else
{
Toast.makeText(E2Activity.this, "sorry ".concat(un).toString().concat(" you are unauthenticated user! "), Toast.LENGTH_LONG).show();
}
}
});
//clear event
final Button btnClear = (Button)findViewById(R.id.cmdClear);
btnClear.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
EditText fldu=(EditText)findViewById(R.id.txtusr);
EditText fldp=(EditText)findViewById(R.id.txtPwd);
fldu.setText("");
fldp.setText("");
}
});
}
}
File Name : Screen2.java
package bsr.e2;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
/** @author Bipin S Rupadiya , www.gtu-android.blogspot.com
**/
public class Screen2 extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent=getIntent();
String uname=intent.getStringExtra("uname");
TextView tv=new TextView(this);
Button btnBack = new Button(this);
btnBack.setText("<<Back");
tv.setText("Welcome "+uname+" !");
tv.setTextColor(Color.rgb(255, 255, 255));
tv.setTextSize(25);
LinearLayout ll = new LinearLayout(this);
ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(tv);
ll.addView(btnBack);
setContentView(ll);
//back event
btnBack.setOnClickListener(new Button.OnClickListener()
{
@Override
public void onClick(View v)
{
setContentView(R.layout.main);
}
});
}
}
Labels:
Android,
Mobile Computing
Subjects
- WordPress
- Mobile Computing-4649303 Practical Solution
- Android Programming New Syllabus Theory
- PHP LAMP Question Bank
- PHP LAMP Theory
- Step by Step Android Example
- Android Practical
- Android Theory
- Android Question Bank
- Networking FON Practical
- Networking FON Theory
- OS Practical
- OS Theory
- HTML
- JavaScript
- J2EE WTAD Theory
- J2EE WTAD Question Bank
- J2EE WTAD Quick Guide
- J2EE WTAD GTU Papers
- J2EE WTAD Practical
- Python
- JAVA Theory
- JAVA Practical
- MIS
Categories
- Android (55)
- c (11)
- Configure Tomcat7 (2)
- CSS (3)
- Decryption (16)
- Difference (1)
- Encryption (16)
- Error Detection and Correction Techniques (3)
- FON (27)
- Framing Technic (2)
- install Tomcat (2)
- J2EE (29)
- JAVA (13)
- JavaScript (19)
- linux (8)
- OS (17)
- PHP (11)
- Protocol (3)
- SERVER SOCKET PROGRAMING (7)
- Servlet (13)
- shell script (33)
- unix (22)
- WTAD (34)
Blog Archive
-
▼
2012
(79)
-
▼
September
(22)
- Chapter 7, Memory Management
- Chapter 6, Concurrency: Deadlock and Starvation
- Chapter 5, Concurrency: Mutual Exclusion and Sync...
- Chapter 4, Threads, SMP, and Micro kernels
- Chapter 3, Process Description and Control
- Chapter 2, Operating System Overview
- Chapter 1, Computer System Overview
- menu in android tutorial
- android animation example
- android chronometer example
- spinner in android example
- listview in android
- implicit intent in android example
- addTextChangedListener in Android example
- Be a Freelances and earn $$$$
- View SQLite Database
- Write a shell script to delete zero sized files fr...
- Android Intent Example
- Hello World in Android
- SQLite Android Tutorial
- Happy Teachers' Day
- Thank you GOD
-
▼
September
(22)
Total Pageviews
© BipinRupadiya.com. Powered by Blogger.