![]() |
intent |
![]() |
intent |
<?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"
android:background="@android:color/holo_blue_light"
tools:context="com.blogspot.csdevbin.explicitintent.Main">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to another activity"
android:id="@+id/button"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="136dp" />
</RelativeLayout>
another.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"
android:background="@android:color/holo_red_dark"
tools:context="com.blogspot.csdevbin.explicitintent.Another">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="go to first activity"
android:id="@+id/button2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="153dp" />
</RelativeLayout>
Main.java
package com.blogspot.csdevbin.explicitintent; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Main extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b1 =(Button)findViewById(R.id.button); b1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent in = new Intent(Main.this,Another.class); startActivity(in); } }); } }
Another.java
package com.blogspot.csdevbin.explicitintent; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Another extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.another); Button b2 =(Button)findViewById(R.id.button2); b2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent in = new Intent(Another.this,Main.class); startActivity(in); } }); } }
Comments :
Post a Comment