Blog purpose for android basic example for android app developer. any query please my contact

Sunday, 5 April 2020

how to move from one activity to another in android

how to move from one activity to another in android

 

In this article, today learn how to move from one activity to another in android intent as using the jump activity one activity to another activity here to any information visit google developer

Here’s a fast guide a way to let the user move between screens in your app. We’ll: add a replacement Activity add a Button that once ironed goes thereto new Activity, mistreatment Associate in Nursing Intent send info between the Activities mistreatment Associate in Nursing Intent further This is basic stuff, however, it could be a core a part of apps therefore worthy of its own post!.


Method  move from one activity to another in android


MainActivity.java:

passButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i =new Intent(MainActivity.this,Second_class.class);
                startActivity(i);
            }
        });
}


Here to using Intent from one activity to another activity in android full Source Code:


Follow the Example how to move from one activity to another in android



1.MainActivity.java:

package com.akash.intent;

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

public class MainActivity extends AppCompatActivity {
Button passButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        passButton=(Button)findViewById(R.id.passButton);

        passButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i =new Intent(MainActivity.this,Second_class.class);
                startActivity(i);
            }
        });
    }
}



2.activity_main.xml:


<LinearLayout 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:padding="15dp"
    android:orientation="vertical">



    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/passButton"
        android:text="Click here jump second clss"/>
</LinearLayout>



3.Second_class.java:

package com.akash.intent;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Second_class extends AppCompatActivity {

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



4.activity_second_class.xml:

<LinearLayout 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:padding="15dp"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textBox"
        android:hint="Welcome Second Activity"/>


</LinearLayout>



5.AndroidManifest.xml:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.akash.intent">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Second_class"></activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>



6.Output:


how to move from one activity to another in android




how to move from one activity to another in android



No comments:

Post a Comment