Creating Custom Views -1

Sometimes you need  different  UI customization on Android .So what will you do except using Android default views ? At this point Android  2D drawing API is coming to help.

Lets start doing this by extending our CustomView class from View class.But don’t forget implement your constructor without  AttributeSet parameter.This parameter let you customize your view after you declare your custom style in resources folder ,With a TypedArray you can continue customize the CustomView at java source code,on the other hand it is possible do this at XML file.

—————————————————————————————-

package com.example.transformations;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class CustomView extends View {

public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Paint mPaint=paintView(Color.GREEN);
canvas.drawRect(50, 50, 200, 150,mPaint);
}

private Paint paintView(int color){
Paint paint=new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(color);
return paint;
}

}

———————————————————————–

On Activity layout define your custom view

<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
xmlns:tools=”http://schemas.android.com/tools&#8221;
android:layout_width=”match_parent”
android:layout_height=”match_parent”
>

<com.example.transformations.CustomView
android:layout_width=”match_parent”
android:layout_height=”match_parent”
/>

</RelativeLayout>

————————————————————————–

device-2014-03-03-205411

Rooting Android

What will you learn                                                      What You Should Know
-Android Security system                                           -Linux OS  knowledge
-Get information about ROM                                      -Android  OS knowledge
-Advantage and Disadvantage of Root

Android is an open platform ,so securing this open platform  requires a robust   security architect.Android has been based on Linux kernel  therefore Android is secure as well  as other Linux release. There is several security features that Linux provides ,these are :

-User based permissions
-Process isolation
-Extensible mechanism for secure IPC(Inter Process Communication)
-The ability to remove unnecessary and insecure pars of the kernel.

Also  Linux operating system isolate user resources from other user.This means  one user can not consume the other users memory ,CPU resources,devices as like GPS,Bluetooth.

Android use these Linux facilities as a means of identifying application resources.Every application running on Android OS are assigned with an user ID ,each Android application runs in a separate process.

By default ,applications can not interact with other applications .If  an application tries to do something harmful as like reading other applications data without permission ,Android prevents this attack.

We can call this system  Android Application Sandbox.You can break the  Android Application Sandbox ,but  this will risk the security of Android.

android ROMS:
When you buy a phone with  Android OS ,it  comes with  its own ROM  ,Android ROM contains Android’s kernel   as well as  operating system libraries,application framework,applications .This partition is set to read-only.

User can  upgrade phones ROM (read only memory)  by flashing many custom ROM  to  their device .There are a lot of  custom ROM  for Android on the  Internet  ,Cyanogen(mod) is the most known aftermarket  customized  firmware distribution for many Android device .If you have  a costly phone and  not expert for  installing custom ROM ,i don’t  suggest  to do this .Instead of this try to find an old tablet or phone.
The benefits of  installing custom ROM is  using the new release of OS  before  your carrier has released. In addition to you can overclock your phone to  increase its performance by installing custom ROM . When you think  flash a custom ROM  do not forget  backup your  stock ROM(firmware),your data .There are some utilities like ROM Manager application on Android Market .After you have downloaded a  custom ROM  image to your  SD card ,you will install  it after rebooting it  in recovery mode by pressing power button and volume-up combination,This combinations can change in some devices.

rooting:

For having  full access to all device  applications and data user must have root permission on Android.If you have root access to your device you can see  and modify all application with  su (super user on linux) command  on adb shell(android debug bridge shell)  .But when you root your device then you will be exposed by all potential  harmful  software.

By having root access on your device you can change your ROM as we have mentioned above.If you have an older version of Android like Android 1.5 Cupcake  you can install a new release of ROM as like Android 2.3 Gingerbread or other new ROMs,nowadays Android  4.0 Ice Cream Sandwich is so popular.

So far  i have explained what is rooting ,you can ask ,how can i root my device ? In one sense there is a lot of device brand that use Android  operating system  on the market .There are some useful  applications  can root your device .They are  working like an Android application ,But nevertheless  there is not  a  standard  way  for doing that ,These applications can root some smart phone but sometimes does not work on others ,specifically Chinese  phone and tablets. I list some application for rooting your devices,these are root applications can root many Android devices:


SuperOneClick  :
This works on both Windows and Linux  PC ,but you should install .net  Framework 2.0 or above .

 

 

 

Universal Androot App : This application runs on device itself ,you don’t need use a usb cable and a software interacting with your device from computer.Just install and root your phone or tablet.It supports many handset model .

 

 

 

 

 

Z4Root : This another one click universal root application for your Android device .

 

 

 

 

 

Advantage and Disadvantage of Root

As we have mentioned earlier ,there is a potential risk of installing malicious application when you root your phone ,so these software may damage your device ,so do not forget install a antivirus application on your Android. Rooting is like jailbreaking on Apple iOS .Rooting can void your phone’s warranty.Additionally ,if rooting doesn’t complete correctly ,it could cause some problem on device.This would require take your phone to factory recover.All of your data could be lost.Do not forget backup your phone’s data.

So far we have talked about disadvantage of rooting .So what are the benefits of root? Root allows you run as superuser ,this gives you full control over the Android Os ,you can change themes,core apps(Google apps) ,backup installed applications to sdcard ,change ROM,Ability to alter system files .Also you change the recovery images with root.

Ibrahim Baran

Singleton Pattern in Java

Singleton design pattern is a creational pattern that ensures there is only one instance of a class and this single class provide a global access point at software .Software programmer generally use this for creating  a single database communication class for accessing to the database  processes.This prevent instantiating  the class more than once for disallow other resource to access database.

I would like to demonstrate this pattern with a car example ,For example all cars only has one steering wheel .Now lets create our singleton steering class .

public class SteeringWheel {

private static SteeringWheel steeringwheel;

private SteeringWheel() {
// by making access modifier of this class’s constructor private ,one instance of this class will be instantiated.
}

//now we create a static method for returning only one instance of our static variable given above

public static synchronized SteeringWheel getSteeringWheelInstace(){

if(steeringwheel==null){
steeringwheel=new SteeringWheel();
}
return steeringwheel;
}

}

After  creating our wheel lets  get instance of this class in our car class .

public class Car {
public static void main(String[] args) {

SteeringWheel isntance1=SteeringWheel.getSteeringWheelInstace();

System.out.println(isntance1);

SteeringWheel instance2=SteeringWheel.getSteeringWheelInstace();

System.out.println(instance2);

}

}

as you see below the output in the console only one instance of class has been created  althought we have two different object reference.

_____________________________________________________________

SteeringWheel@30c221
SteeringWheel@30c221

______________________________________________________________

now lets  instantiate our  SteeringWheel class with  “new”  ,this will cause error because our class constructor is private so this doesn’t let us to create more than one instance.

Error looks like this

_______________________________________________________________

Exception in thread “main” java.lang.Error: Unresolved compilation problem:
The constructor SteeringWheel() is not visible

at Car.main(Car.java:15)

_______________________________________________________________

Factory Method Example

The  Factory Method  is a creational  pattern which usage frequency is high in software development .This pattern provides  an abstraction to lets  subclass decide which  class should be instantiated.Here i created an example that demonstrate this creational pattern.

In this example ,i  would like to create a garden which it is trees are created by  Factory Method Pattern,and this garden has two species  of fruit tree ,you can add more  tree species to your garden.

STEP-1:  

I need a product template  like in factory ,factory is our garden so the product is  fruit here ,create an abstract  class ;
public abstract class Fruit {

String name;
public Fruit(String name) {
this.name=name;
}

public String getFruitName(){

return this.name;
}

}

STEP-2:

Now , we create our fruit species  which extending  from the  Fruit  abstract class ;

public class Apple extends Fruit {

String name;

public Apple(String name) {

super(name);

}

}

Another fruit can be  a cherry ;

public class Cherry extends Fruit{

String name;
public Cherry(String name) {
super(name);
}

}

STEP-3:

We created our species ,as i have mentioned above you can add more by deriving it from Fruit abstract class ,then we know this fruits are growth on trees  ,So i need  a tree template as like Fruit ,with this template i will produce   different fruit trees for my garden ,our factory method starts here ,you will then override it by extending it to your subclass ,and this will let you to specify your class which you would create.

public abstract class TreeCreator {

public abstract Fruit factoryNethod();
}

Now we express our tree species  for fruits we have created above ;
public class AppleTree extends TreeCreator {

@Override
public Fruit factoryNethod() {
// TODO Auto-generated method stub
return new Apple(“Apple”);
}

}

same thing for cherry tree ;

public class CherryTree extends TreeCreator {

@Override
public Fruit factoryNethod() {
// TODO Auto-generated method stub
return new Cherry(“Cherry”);
}

}

STEP-4:

Eventually  we are ready to create our fruit garden ,this is a good place for writing our main method ,

public class Garden {

public static void main(String[] args) {

//neeed some trees in my garden call treecreators,an array would be a good choice

TreeCreator tCreators[]=new TreeCreator[4];
tCreators[0]=new AppleTree();
tCreators[1]=new CherryTree();
tCreators[2]=new CherryTree();
tCreators[3]=new AppleTree();

for (TreeCreator treeCreator : tCreators) {
Fruit f=treeCreator.factoryNethod();
System.out.println(f.getFruitName());
}

}

}

—————————————————————————————–

The output look like this  :

Apple
Cherry
Cherry
Apple

How To Open Wireless Preference Screen Programatically and Automatically on Android

For  switching to wireless preference screen  in Android you  can add these lines to your  on an action event .

btnSetWifi.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

final ComponentName toLaunch = new ComponentName(“com.android.settings”,”com.android.settings.wifi.WifiSettings”);
final Intent intent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.setComponent(toLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(intent, 0);
}
});

Or ,if  you would  open wifi  after your activity created automatically ,this can be done by adding this code lines ,this will open wifi automatically at the background. I added it  oncreate state in activity.

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Intent autowifi = new Intent();
autowifi.setClassName(“com.android.settings”,
“com.android.settings.widget.SettingsAppWidgetProvider”);
autowifi.addCategory(Intent.CATEGORY_ALTERNATIVE);
autowifi.setData(Uri.parse(“0”));
this.sendBroadcast(autowifi);

}

Android Animations

While develop your application ,sometimes you need some fascinating things on your application ,for  performing this job  Android supply developers to enhance their user interface with its animation feature.After  apply this tutorial yourself ,you  will be able to write your animation as you want.

main.xml

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>

<ListView
android:id=”@+id/carlist”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
/>

</LinearLayout>


create  a folder name  “anim” under  “res”  and  create the  rowanimation file  inside it.  ( res/anim/rowanimation.xml)

rowanimation.xml  : 

<?xml version=”1.0″ encoding=”utf-8″?>

<set xmlns:android=”http://schemas.android.com/apk/res/android”&gt;

<scale
android:fromXScale=”1.0″ android:toXScale=”3.0″
android:fromYScale=”1.0″ android:toYScale=”3.0″
android:pivotX=”50%”
android:pivotY=”50%”
android:fillAfter=”false”
android:duration=”5000″ />

<rotate
xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:fromDegrees=”0″
android:toDegrees=”360″
android:toYScale=”0.0″
android:pivotX=”50%”
android:pivotY=”0%”
android:duration=”5000″ />

</set>

here i defined two animation type in a set , However ,you can define other animation like alpha and translate  in your animation file.


On  code side we modify our main activity

AnimatonTime.java

package com.toto.loto;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class AnimatonTime extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

String [] liste={“Mercedes “,”Toyota”,”Auidi”,”BMW”
,”Hyundai”,”KIA”,”Land Rover”,”Ferrari”,”Porche”
,”Subarru”,”SAAB”,”Opel”,”Wolkswagen”,”Nissan”};

ListView lv=(ListView)findViewById(R.id.carlist);

final Animation rowtanimation=AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rowanimation);

lv.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_expandable_list_item_1, liste));

lv.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View v, int arg2,
long arg3) {

v.startAnimation(rowtanimation);

}
});
}
}

 


Output :

A simple Android SQLite3 example

I would like create a project concerning with Android SQLite3 database  ,this project  aims to show how save our application data permanently.


our layout definition main.xml ;

<?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"
    >
<TextView
    android:id="@+id/result"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
</LinearLayout>

our main activity DBExample.java ;

package com.bambu.tom;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources.Theme;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.util.Log;
import android.widget.TextView;

public class DBExample extends Activity {
    private SQLiteDatabase db;
	private TextView tv;
	private ProgressDialog pd;
	private StringBuilder builder;
	private Thread th ;
	Handler handler=new Handler(){

		public void handleMessage(android.os.Message msg) {
		    pd.dismiss();

		    // to ensure kill our thread
		    if(th!=null){
		    	Thread temp=th;
		    	th=null;
		    	temp.interrupt();
		    }

			tv.setText(builder);

		};
	};
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         tv=(TextView)findViewById(R.id.result);

         pd=ProgressDialog.show(DBExample.this, "Retrieving data from database", "");
         th=new Thread(new Runnable() { // threading for long time data retrieving

			@Override
			public void run() {

				db=(new MyDBHelper(DBExample.this)).getReadableDatabase();

	  	        Cursor cur=db.rawQuery("Select * from grades",null);

	  	        cur.moveToFirst();
	  	        builder=new StringBuilder();
	  	        while (!cur.isAfterLast()) {

	  	        	builder.append(Integer.toString(cur.getInt(0))+"-"+
	  	        			cur.getString(cur.getColumnIndex(MyDBHelper.NAME_COL))+"-" +  //getting name string  with table column name
	  	        			Double.toString(cur.getDouble(2))+"\n");  // also you can get grade with table column index
	  	        	cur.moveToNext();
	  	        	try {
						Thread.sleep(1000); // you dont need this
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
	  			}
	  	       cur.close();
	  		   handler.sendEmptyMessage(0);

			}
		});

       th.start();

    }

    private class MyDBHelper extends SQLiteOpenHelper{ // we define our database helper as inner class 

    	public static final String DB_NAME="bambu";
        public static final String ID_COL="_id";
        public static final String NAME_COL="name";
        public static final String GRADE_COL="grade";
        public static final String TABLE_NAME="grades";
        public String SQL_SCRIPT ="CREATE TABLE "+TABLE_NAME+ "( "+ID_COL+" INTEGER PRIMARY KEY AUTOINCREMENT,"+NAME_COL +" TEXT,"
                                   +GRADE_COL+" REAL"+")";

    	public MyDBHelper(Context context) {
			super(context, DB_NAME, null,1 );
			// TODO Auto-generated constructor stub
		}

    	@Override
    	public void onCreate(SQLiteDatabase db) {

    	   db.execSQL(SQL_SCRIPT);
     	   ContentValues cv=new ContentValues(); // content holder for inserting data to database
    	   //lets populate our table after create grades 

    	   Map<String, Double> table=new HashMap<String, Double>();
    	   table.put("KIM",new Double(72.10));
    	   table.put("RANGO", new Double(52.50));
    	   table.put("STEPHANIE", new Double(45.0));
    	   table.put("FRED", new Double(95.0));
    	   table.put("TOM", new Double(75.0));
    	   table.put("JERRY", new Double(45.0));
    	   table.put("TIGER", new Double(25.0));
    	   table.put("ROADRUNNER", new Double(100.0));
    	   table.put("BARNİE", new Double(45.0));
    	   table.put("TED", new Double(45.0));

    	   Set st=table.entrySet();

    	   Iterator it=st.iterator();

    	   while (it.hasNext()) {

    		  Map.Entry m=(Map.Entry)it.next();

    		  String name=(String)m.getKey();  // get name as value

    		  Double grade=(Double)m.getValue(); // get grade as value
    		   cv.put(NAME_COL, name);
        	   cv.put(GRADE_COL, grade);
        	   db.insert(TABLE_NAME, NAME_COL, cv);

		}

    	}

    	@Override
    	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    	}

    }

output look like below ;

Creating and Reading a File in Android

You can  create files in your application easily .This example will demonstrate how to  create ,write and read a text file in Android operating system.

Our layout file main.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">
    <EditText
     android:id="@+id/myText"
      android:layout_height="wrap_content"
       android:layout_width="match_parent"
       android:singleLine="false" android:layout_weight="4"></EditText>
    <Button
    android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/btnCreate" android:text="Create File" android:layout_weight="1"></Button>

        <Button
    android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:id="@+id/btnRead" android:text="ReadFile" android:layout_weight="1"></Button>

</LinearLayout>

Our Main activity look like this ;

package com.re.wr;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Write extends Activity {
    /** Called when the activity is first created. */
	EditText myText;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myText =(EditText)findViewById(R.id.myText);
        Button  createButton=(Button)findViewById(R.id.btnCreate);
        Button readButton=(Button)findViewById(R.id.btnRead);
        createButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				createFile(myText.getText().toString());
				myText.setText("");
			}
		});

        readButton.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {

				readFile();

			}
		});
    }

    private void createFile(String Text){

    	FileOutputStream fos=null;
    	try {
			fos=openFileOutput("mynote.txt", MODE_PRIVATE);
			fos.write(Text.getBytes());
			Toast.makeText(getApplicationContext(), "File created succesfully", Toast.LENGTH_SHORT).show();
		} catch (FileNotFoundException e) {
			 Log.e("CreateFile", e.getLocalizedMessage());
		}
		catch (IOException e) {
			 Log.e("CreateFile", e.getLocalizedMessage());
		}

		finally{
			if(fos!=null){
				try {
					// drain the stream
					fos.flush();
					fos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
    }

    private void readFile(){

    	FileInputStream fis;

    	try {
			fis=openFileInput("mynote.txt");
			byte[] reader=new byte[fis.available()];
			while (fis.read(reader)!=-1) {

			}
		    myText.setText(new String(reader));
		    Toast.makeText(getApplicationContext(), "File read succesfully", Toast.LENGTH_SHORT).show();
		    if(fis!=null){
		    	fis.close();
		    }
		}
    	catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		catch (IOException e) {
			Log.e("Read File", e.getLocalizedMessage());
		}

    }

}

The output look like this ,

Starting Activity For Result

Sometimes we need   grasp  a result value  when switch between  activities,when we start an activity for getting a result  we call the  startActivityForResult(intent, requestCode)   method .This method takes two parameters ; the first one is  the intent that we would like to launch  ,the latter is  a primitive code we declare at the begining of our activity class. After launching the intent at this function our new activity come to foreground ,when we finish our processes  on current activity  we override  onActivityResult method like below ;

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data)

{

// TODO Auto-generated method stub

super.onActivityResult(requestCode, resultCode, data);

}

For understanding this  feature we create a new project on our Eclipse workbench.


ProjectName: ActivityForResult

Android API Level:  8

Platform : 2.2


Step-1: Prepare the  Layout  on main.xml

<?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"
    >

  <Button
   android:id="@+id/startActForResult"
   android:text="StartActivityForResult"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"/>

  <TextView
   android:id="@+id/resultText"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:layout_marginTop="10dip"/>
</LinearLayout>

Step-2:Modify your launchedlayout.xml   to use for  LaunchedActivity.java ,

 <?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">
  <TextView
  android:text="Enter the text you want to pass calling activiy"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>

  <EditText
  android:id="@+id/passText"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
  <Button
  android:id="@+id/createResult"
  android:text="ActForResult"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center"/>  
</LinearLayout>

Step-3:  we  create a new activity for postback a result to the calling activity ,our launched class is ,LaunchedActivity.java;

package com.baran;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LaunchedActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {

	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.launchedlayout);

	    final EditText passEditText=(EditText)findViewById(R.id.passText);
	    Button createResButton=(Button)findViewById(R.id.createResult);
	    createResButton.setOnClickListener(new View.OnClickListener() {

	    @Override
	    public void onClick(View arg0) {

	    // catch the intent that started this activity
	    Intent i=getIntent();
	    i.putExtra("mytext", passEditText.getText().toString());
            setResult(RESULT_OK, i);
	    finish();
	}
      });
    }

}

When finish LaunchedActivity activity it passes the data by setResult() method ,then it gets this data at onActivityResult() method  for  using it.Our calling activity is ActForRes.java ;

package com.baran;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class ActForRes extends Activity {
    /** Called when the activity is first created. */
	private static final int LAUNCH_REQCODE=1500;
	private TextView tv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv=(TextView)findViewById(R.id.resultText);
        Button btnActForResult=(Button)findViewById(R.id.startActForResult);

        btnActForResult.setOnClickListener(new View.OnClickListener() {

		@Override
		public void onClick(View arg0) {
				// TODO Auto-generated method stub

				startAction();
	        }
	 });

    }

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(requestCode==LAUNCH_REQCODE && resultCode==RESULT_OK){
      tv.setText(data.getExtras().getString("mytext"));
    }
    super.onActivityResult(requestCode, resultCode, data);

    }

    private void startAction(){
    Intent launchIntent =new Intent(this,LaunchedActivity.class);
    startActivityForResult(launchIntent,LAUNCH_REQCODE);

    }
}

Result: