Hey guys I am trying to create a game where when a condition is met the the Activity is called and now runs level 2 conditions, and so on as the levels increment. The problem is that the level integer which stores the level always resets to the initialised value, I basically want to call the intent if the level up condition is met, reload the activity and increment the level integer.
I cannot figure out how to do this, here is my activity which I want to call:
package com.deucalion0;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class FirstOneActivity extends Activity {
/** Called when the activity is first created. */
MediaPlayer ourSong;
int counter;
Button add;
Thread timer;
TextView display;
TextView lvl;
int level = 1;
int time;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ourSong = MediaPlayer.create(FirstOneActivity.this, R.raw.click);
counter = 0;
add = (Button) findViewById (R.id.bAdd);
display = (TextView) findViewById (R.id.tvDisplay);
lvl = (TextView) findViewById (R.id.lvldisplay);
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
counter++;
//ourSong.start();
display.setText("Your total is "+ counter);
if(counter ==1)
{
set();
timer.start();
}
}
});
timer = new Thread(){
public void run(){
try{
sleep(time);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
test();
}
}
};
}
public void test(){
if(counter>= 10 && level == 1 || counter>= 15 && level == 2)
{
Intent openSplash = new Intent("com.deucalion0.FIRSTONE");
startActivity(openSplash);
level++;
}
else if(counter<10 && level == 1 || counter< 15 && level == 2){
Intent openNext = new Intent("com.deucalion0.NEXT");
startActivity(openNext);
}
}
public void set(){
if(level == 1)
{ lvl.setText("Level is "+ level);
time = 5000;
}
else if (level == 2)
{lvl.setText("Level is "+level);
time = 5000;
}
}
}
I would appreciate any help at all.
Many thanks!