How to call Custom Activity inside onCreate method - java

I am developing a simple app that has two activities, MainActivity and SecondActivity and a transparent CustomActivity that extends Dialog. The
MainActivity has two buttons (Yes_button and No_button).
When user clicks Yes_button, the SecondActivity is called via Intent and the
CustomActivity will be in front of it.
When user clicks No_button the SecondActivity will also be called but the CustomActivity will not be called alongside with it.
The calling of the CustomActivity is based on if-else statement expressions. The CustomActivity has a skip button, when clicked the CustomActivity will close only then can the SecondActivity be accessible to the user. The SecondActivity has just one button that calls the MainActivity and the cycle continues.
Problem
When the app launches and a user clicks on the No_button, the SecondActivity will be called without the CustomActivity (as expected!), but ONCE a user
clicks on the Yes_button, the SecondActivity will keep on displaying alongside the CustomActivity EVEN when the No_button is clicked.
Expectation
I want the SecondActivity to be called alongside the CustomActivity each time the Yes_button is clicked and also let only the SecondActivity be called when ever the No_button is click.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xml:toos="http://schemas.android.com/tools">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/button1" />
</RelativeLayout>
MainActivity.java
public class MainActivity extends BaseActivity implements View.OnClickListener {
private static int getNumber;
Button Yes_button;
Button No_button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Yes_button = findViewById(R.id.button1);
No_button = findViewById(R.id.button2);
Yes_button.setOnClickListener(this);
No_button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1:
int get_input = 1; // will be use in if else statement.
getNumber = get_input;
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent);
break;
case R.id.button2:
Intent intent2 = new Intent(MainActivity.this, SecondActivity.class);
startActivity(intent2);
break;
}
}
public static int get_Logic() {
return getNumber;
}
}
activity_second_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xml:toos="http://schemas.android.com/tools">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text"
android:onClick="Click"
android:text="Click" />
</RelativeLayout>
SecondActivity.java
public class SecondActivity extends AppCompatActivity {
private static int output;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_activity);
int received = MainActivity.get_Logic();
output = received;
Display();
}
public final void Display() {
if (output == 1) {
CustomActivity custom = new CustomActivity(SecondActivity.this);
custom.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
custom.show();
} else {
CustomActivity custom = new CustomActivity(SecondActivity.this);
custom.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
custom.cancel();
}
}
public void Click(View view) {
Intent intent = new Intent(SecondActivity.this, MainActivity.class);
startActivity(intent);
}
}
activity_custom_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="180dp"
android:layout_height="250dp"
xml:toos="http://schemas.android.com/tools">
<TextView
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text"
android:text="Skip" />
</RelativeLayout>
CustomActivity.java
class CustomActivity extends Dialog {
Button SkipButton;
private Activity main;
public CustomActivity(Activity constr) {
super(constr);
this.main = constr;
}
#Override
protected void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setCancelable(false);
setContentView(R.layout.activity_custom_activity);
SkipButton = findViewById(R.id.button);
SkipButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dismiss();
}
});
}
}
checking.xml
<?XML version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#FFFF" />
<corners android:radius="20dp" />
<stroke android:width="4dp" android:color="#color/colorPrimary" />
<gradient />
</shape>
</item>
</selector>

In Android, to pass data from an activity to another, you don't need to declare a static variable (getNumber in MainActivity), you should use Intent and Bundle together. See the below solution.
MainActivity.java
public class MainActivity extends BaseActivity implements View.OnClickListener {
Button Yes_button;
Button No_button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Yes_button = findViewById(R.id.button1);
No_button = findViewById(R.id.button2);
Yes_button.setOnClickListener(this);
No_button.setOnClickListener(this);
}
#Override
public void onClick(View v) {
int input = v.getId() == R.id.button1 ? 1 : 0;
Intent intent = new Intent(MainActivity.this, SecondActivity.class);
intent.putExtra("input", input);
startActivity(intent);
}
}
SecondActivity.java
public class SecondActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second_activity);
Display();
}
public final void Display() {
int input = getIntent().getIntExtra("input", 0);
CustomActivity custom = new CustomActivity(SecondActivity.this);
custom.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
if (input == 1) {
custom.show();
} else {
custom.cancel();
}
}
public void Click(View view) {
finish();
}
}

Related

setVisibility() in onClick() makes app crash

I'm trying to show pic after pressing ImageButton, but when I test it on my phone it just crashes and drops me on previous Activity.
There are some more Activities, but each of them works normally.
ActionActivity.java
public class ActionActivity extends AppCompatActivity implements View.OnClickListener {
ImageButton PhotoHint;
ImageView PhotoPic;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.action);
ImageButton PhotoHint = (ImageButton) findViewById(R.id.PhotoHint);
ImageView PhotoPic = (ImageView) findViewById(R.id.Photo);
PhotoPic.setVisibility(View.INVISIBLE);
PhotoHint.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.PhotoHint:
PhotoPic.setVisibility(View.VISIBLE);
}
}
}
action.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
...
<FrameLayout
android:id="#+id/frameLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/Photo"
android:layout_width="189dp"
android:layout_height="169dp"
android:layout_gravity="center"
android:background="#drawable/somepic"
/>
<ImageButton
android:id="#+id/PhotoHint"
android:layout_width="42dp"
android:layout_height="wrap_content"
android:layout_gravity="center|bottom"
app:srcCompat="#android:drawable/ic_menu_gallery" />
</FrameLayout>
</LinearLayout>
try now it will work fine...
the problem was with this line
ImageButton PhotoHint = (ImageButton) findViewById(R.id.PhotoHint);
ImageView PhotoPic = (ImageView) findViewById(R.id.Photo);
they were not globally initialized that's why you were facing crash.!
public class ActionActivity extends AppCompatActivity implements View.OnClickListener {
ImageButton photoHint;
ImageView photoPic;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.action);
photoHint = (ImageButton) findViewById(R.id.PhotoHint);
photoPic = (ImageView) findViewById(R.id.Photo);
photoPic.setVisibility(View.INVISIBLE);
photoHint.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.PhotoHint:
photoPic.setVisibility(View.VISIBLE);
}
}
}

How can I implement a java method in to return the activity to the mainActivity?

I have my code for a simple activity to return to the main activity once the user clicks on the home button.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_greetings);
// Set up onclicklistener for homeIcon imageview to go to back one activity
ImageView homeIcon = (ImageView) findViewById(R.id.home_icon);
homeIcon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
This is a java file for a single activity, greetings. I want this home button + functionality for many other activities, but I do not want to copy and paste. Should I make another java class, and implement the function inside of it? I tried, but it can not findviewbyid.
Without your code really hard understand why you can not find by id, but I can offer this way:
HomeButtonActivity.java
public class HomeButtonActivity extends AppCompatActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Button home_button = (Button) findViewById(R.id.home_button);
home_button.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
Toast.makeText(HomeButtonActivity.this, "Replace with your own action", Toast.LENGTH_SHORT).show();
}
});
}
}
Activity1.java
public class Activity1 extends HomeButtonActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.activity1);
super.onCreate(savedInstanceState);
}
}
activity1.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.myapplication.HomeButtonActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
<include layout="#layout/home_button" />
</android.support.design.widget.CoordinatorLayout>
home_button.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:text="home button"/>
create class e.g ReturnClass and create constructor for it, then pass Context as parameter e.g ReturnClass(Context context) then write
Intent intent = new Intent(context , MainActivity.class);
context.startActivity(intent);
from each activity you can call this class and pass activity to it , and ReturnClass return it to main activity

Android Progress Bar not working

I have made a progress bar in Android but it is not at all working. What am I doing wrong? I have just started to learn android. Below is my code.
MainActivity.java-
public class MainActivity extends AppCompatActivity {
ProgressBar progressBar;
int mporgress=0;
EditText time;
private Handler mHandler = new Handler();
private static final int PROGRESS = 0x1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Startbuttononclick(View view){
Button startbutton=(Button) findViewById(R.id.button);
startbutton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
mporgress = Integer.parseInt(time.getText().toString());
progressBar.setProgress(mporgress);
new Thread(new Runnable() {
public void run() {
while (mporgress < 100) {
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
progressBar.setProgress(mporgress);
mporgress = doWork();
try{
Thread.sleep(1000);
}catch (InterruptedException e){}
}
});
}
}
}).start();
}
});
}
public void doprogress(View view) {
}
public int doWork(){
mporgress++;
return mporgress;
}
}
Activity_main.xml-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.android.progressbar.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter the time:"
android:inputType="number"
android:id="#+id/editText" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="500dp"
android:layout_height="200dp"
android:id="#+id/progressBar4"
android:layout_gravity="center"
android:scrollbarSize="500dp" />
<Button
android:text="START"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_gravity="center"
android:onClick="Startbuttononclick" />
</LinearLayout>
Check out this image below-
- https://i.stack.imgur.com/2TBIb.png
Note- Enter the time in this image is an EditText with a hint and not a TextView.
It is appearing but not working.
I have done these changes so far.-
https://i.stack.imgur.com/UujpB.png
But still the progress bar is still continuously rotating.
Seems you forgot to initialize EditText -time and ProgressBar. Init it inside onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar =(ProgressBar) findViewById(R.id.progressBar4);
time = (EditText) findViewById(R.id.editText); //here
}
Also inside button click the bar:
progressBar = new ProgressBar(this);
mporgress = Integer.parseInt(time.getText().toString());
................
.............

menu using clickable images?

I'm trying to create a menu using clickable images, but they don't seem to be working? I was following a tutorial and it uses something like
Intent biodata = new Intent(mainActivity.this, profile.class);
but it's not working so I tried to look for something else and someone said to use v.getContext() instad of ....this
it works on my other page but it doesn't work on this page?
mainActivity.java
package skripsi.garden;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
public class mainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public ImageButton buttonBio;
public void init(){
buttonBio= (ImageButton)findViewById(R.id.buttonBio);
buttonBio.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent biodata = new Intent(v.getContext(), profile.class);
startActivity(biodata);
}
}
);
}
public ImageButton buttonList;
public void tombollist(){
buttonList=(ImageButton)findViewById(R.id.buttonList);
buttonList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent listTaman = new Intent(v.getContext(), gardenlist.class);
startActivity(listTaman);
}
}
);
}
public ImageButton buttonWeather;
public void tombolcuaca(){
buttonWeather=(ImageButton)findViewById(R.id.buttonWeather);
buttonWeather.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cuaca = new Intent(v.getContext(), weather.class);
startActivity(cuaca);
}
}
);
}
}
and this is the xml
activity_main.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="#drawable/foliagemain"
tools:context="skripsi.garden.mainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView3"
android:src="#drawable/selamatdatang"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonBio"
android:src="#drawable/buttonbiodata"
android:layout_above="#+id/buttonList"
android:layout_alignRight="#+id/buttonWeather"
android:layout_alignEnd="#+id/buttonWeather" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonList"
android:src="#drawable/buttondaftartaman"
android:layout_above="#+id/buttonHelp"
android:layout_alignLeft="#+id/buttonHelp"
android:layout_alignStart="#+id/buttonHelp" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonHelp"
android:src="#drawable/buttonhelp"
android:layout_above="#+id/buttonWeather"
android:layout_alignLeft="#+id/buttonBio"
android:layout_alignStart="#+id/buttonBio" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonWeather"
android:src="#drawable/buttoncuaca"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Put your buttons in your onCreate method. They do not need to be in their own method.
public class mainActivity extends AppCompatActivity {
public ImageButton buttonBio;
public ImageButton buttonList;
public ImageButton buttonWeather;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonBio= (ImageButton) findViewById(R.id.buttonBio);
buttonBio.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent biodata = new Intent(mainActivity.this, profile.class);
startActivity(biodata);
}
});
buttonList=(ImageButton)findViewById(R.id.buttonList);
buttonList.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent listTaman = new Intent(mainActivity.this, gardenlist.class);
startActivity(listTaman);
}
});
buttonWeather=(ImageButton)findViewById(R.id.buttonWeather);
buttonWeather.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent cuaca = new Intent(mainActivity.this, weather.class);
startActivity(cuaca);
}
});
}
}
You could just call your methods init(), tombollist() and tombolcuaca() in onCreate method of your activity after setting the layout.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
init();
tombollist();
tombolcuaca()
}
This would initialise the button to do the action written inside the onClick.
If the methods are not called, the button would not be initialised and hence the click will not work.
You could also use android:clickable="true" in your imageButtons, and then assign the click function init() to the button in your layout xml.
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonBio"
android:src="#drawable/buttonbiodata"
android:layout_above="#+id/buttonList"
android:layout_alignRight="#+id/buttonWeather"
android:layout_alignEnd="#+id/buttonWeather"
android:clickable="true"
android:onClick="init"/>
Then you wouldn't need to initialise the buttons in your activity. On click of the button, the method would be called.

Cannot change TextView between two activities?

I'm attempting to change a TextView between two activities. The problem is, when I change the text in the other activity from main activity, it works fine, the screen goes to the other activity and the text has been changed. However I have another button which takes me to the other activity from Main, but the newly updated text has disappeared when I press it. Any help?
MyActivity.java
public class MyActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
final EditText et = (EditText) findViewById(R.id.editText1);
Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(MyActivity.this, Second.class);
intent.putExtra("thetext", et.getText().toString());
startActivity(intent);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void onClickGoToActivity(View view) {
setContentView(R.layout.second);
}
}
Second.java
public class Second extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(getIntent().getExtras().getString("thetext"));
}
}
activity_my.xml
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MyActivity">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText1"
android:layout_centerHorizontal="true"
android:hint="Change me"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button1"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:text="Add text in other activity"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/go_to_activity_button"
android:text="Go to activity"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dp"
android:onClick="onClickGoToActivity"/>
</RelativeLayout>
second.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView1"
android:textSize="30sp"/>
</LinearLayout>
AndroidManifest.xml
Second class activity:
I presume the problem lies here:
public void onClickGoToActivity(View view) {
setContentView(R.layout.second);
}
where the newly changed TextView is being reset back to the original layout (where the TextView is empty with no text). I'm not sure how to fix this as I'm new to Android.
Thank you.
changing content view of activity is a bad idea to start another activity. Simply you just do the same thing which is
public void onClickGoToActivity(View view) {
Intent intent = new Intent(MyActivity.this, Second.class);
intent.putExtra("thetext", et.getText().toString());
startActivity(intent);
}

Categories

Resources