To Develop App demonstrating transfer of Data between multiple Activities > Android App Development

To Develop App demonstrating transfer of Data between multiple Activities > Android App Development

Mobile Communication and Computing

Programs:


activity_main1.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.prathameshpandit.practiceapplication1.MainActivity1">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="textPersonName"
        android:text=""
        android:ems="10"
        android:id="@+id/editText"
        android:layout_above="@+id/editText2"
        android:layout_alignStart="@+id/editText3"
        android:layout_marginBottom="70dp" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/editText3"
        android:layout_above="@+id/NEXT"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="68dp" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NEXT"
        android:id="@+id/NEXT"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:onClick="ClickMe"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter Name, Branch and Roll Number"
        android:id="@+id/textView3"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:editable="false" />
</RelativeLayout>


MainActivity1.java

package com.example.prathameshpandit.practiceapplication1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity1 extends AppCompatActivity {
    EditText name,branch,no;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);

        name=(EditText)findViewById(R.id.editText);
        branch=(EditText)findViewById(R.id.editText2);
        no=(EditText)findViewById(R.id.editText3);
    }

    public void ClickMe(View v){
        String str=" Student "+name.getText().toString()+" Studying in Branch "+branch.getText().toString()+" having Roll Number "+no.getText().toString();
        Intent i=new Intent(MainActivity1.this,MainActivity2.class);
        i.putExtra("Detail", str);
        startActivity((i));

    }
}


activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.prathameshpandit.practiceapplication1.MainActivity2">

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/editText4"
        android:layout_above="@+id/editText5"
        android:layout_marginBottom="57dp"
        android:layout_alignEnd="@+id/editText5"
        android:layout_alignStart="@+id/editText5" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/editText5"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number"
        android:ems="10"
        android:id="@+id/editText6"
        android:layout_marginBottom="99dp"
        android:layout_above="@+id/BACK"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="BACK"
        android:id="@+id/BACK"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:onClick="ClickMeB"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NEXT"
        android:id="@+id/NEXT"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:onClick="ClickMeN"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Enter Marks for Physics, Chemistry and Math"
        android:id="@+id/textView4"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

</RelativeLayout>


MainActivity2.Java

package com.example.prathameshpandit.practiceapplication1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity2 extends AppCompatActivity {

    EditText phy,chem,math;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        phy=(EditText)findViewById(R.id.editText4);
        chem=(EditText)findViewById(R.id.editText5);
        math=(EditText)findViewById(R.id.editText6);
    }
    public void ClickMeB(View v){
        Intent i=new Intent(MainActivity2.this,MainActivity1.class);
        startActivity(i);
    }
    public void ClickMeN(View v){
        int p,c,m,tot;
        Intent i1=getIntent();
        String x=i1.getStringExtra("Detail");
        p=Integer.parseInt(phy.getText().toString());
        c=Integer.parseInt(chem.getText().toString());
        m=Integer.parseInt(math.getText().toString());
        tot=p+c+m;
        Intent i=new Intent(MainActivity2.this,MainActivity3.class);
        String y=x+" had Scored a Total of "+tot+" in PCM !!";
        i.putExtra("Summary", y);
        startActivity(i);
    }
}


activity_main3.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.prathameshpandit.practiceapplication1.MainActivity3">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView2"
        android:layout_marginTop="49dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="BACK"
        android:id="@+id/BACK"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:onClick="ClickMeB"/>

</RelativeLayout>


MainActivity3.java

package com.example.prathameshpandit.practiceapplication1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class MainActivity3 extends AppCompatActivity {

    TextView tv;   String c;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        tv=(TextView)findViewById(R.id.textView2);
        Intent i1;
        i1=getIntent();
        c=i1.getStringExtra("Summary");
        tv.setText(c);

    }
    public void ClickMeB(View v)
    {

        Intent i=new Intent(MainActivity3.this,MainActivity2.class);
        startActivity(i);
    }
}

App ScreenShots:



Comments

Popular posts from this blog

Intermediate Code Generation > C Program