My question is relative to this question Clearing intent but I'm having problems implementing it.
My first class TodaysExercise.java
has a button, when the button is clicked I putExtra intent.putExtra("highlegs", "High Legs");
and startActivity(intent);
TodaysExercise.java
final Intent intent = getIntent();
if (intent != null) {
String clicked = intent.getStringExtra("button");
if (clicked.equals("btn1")) {
intent.setClass(TodaysExercise.this, DoExercise.class);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//When btn1 is clicked I putExtra
intent.putExtra("highlegs", "High Legs");
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
});
}
}
The next class DoExercise.java
then get the string String text = bundle.getString("highlegs");
and set it to the textView textView.setText(text);
. I then check if TextView is equal to if (textView.getText().equals("High Legs"))
and if it is, I once again putExtra i.putExtra("next", "Leg Curls X 20");
and start next class startActivity(intent);
DoExercise.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_do_the_exercise);
textView = (TextView) findViewById(R.id.replace_this);
descheader = (TextView) findViewById(R.id.desc_header_id);
fab = (FloatingActionButton) findViewById(R.id.fab);
Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/countdown.ttf");
descheader.setTypeface(custom_font);
toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String text = bundle.getString("highlegs");
if (text != null)
textView.setText(text);
}
if (textView.getText().equals("High Legs"))
{
ImageView imLoading = (ImageView) findViewById(R.id.loadingView);
imLoading.setBackgroundResource(R.drawable.workout);
AnimationDrawable frameAnimation = (AnimationDrawable) imLoading
.getBackground();
frameAnimation.start();
final Intent i = new Intent();
i.setClass(DoExercise.this, ReadyForNext.class);
fab.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
i.putExtra("next", "Leg Curls X 20");
startActivity(i);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
}
});
}
I get String text = bundle.getString("next");
and set tv_nextdesc.setText(text);
the string extras to the TextView. I also have a button in this class that should return to DoExercise.java
and this is where my question is.
ReadyForNext.java
public class ReadyForNext extends AppCompatActivity {
Button btn_next_exercise;
TextView tv_nextdesc;
TextView tv_nexttxt;
Context f;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ready_for_next);
btn_next_exercise = (Button) findViewById(R.id.btn_next_exercise);
tv_nextdesc = (TextView) findViewById(R.id.tv_nextdesc);
tv_nexttxt = (TextView) findViewById(R.id.nxtTxt);
Typeface custom_font = Typeface.createFromAsset(getAssets(), "fonts/countdown.ttf");
tv_nextdesc.setTypeface(custom_font);
tv_nexttxt.setTypeface(custom_font);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
String text = bundle.getString("next");
if (text != null)
tv_nextdesc.setText(text);
}
final Intent i = new Intent();
i.setClass(ReadyForNext.this, DoExercise.class);
btn_next_exercise.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//I first check what the title is to determine what to put extra
if (tv_nextdesc.getText().equals("Leg Curls X 20")) {
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
//then here I putExtra
i.putExtra("legcurls", "Leg Curls");
startActivity(i);
}
}
});
}
So as you can see I have 3 classes that basically run in a circle, TodaysExercise.java
opens DoExercise.java
and it opens ReadyForNext.java
from here I want to open DoExercise.java
again (Reuse DoExercise.java) but that is when I want to clear the intent to put a new intent extra?
Any help on how to achieve this?