Я пытался найти решение этой проблемы, но я не нашел.Вопрос в том, чтобы вернуться к Activity из View .Как только , если оператор станет false , он должен вернуть меня к SplashActivity Здесь некоторые классы Activity и View, которые выполняют всю логику изapplication.
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
GameEngine gameEngine = new GameEngine(this);
setContentView(gameEngine);
}
}
Затем идет мой SplashActivity с одним ImageButton , который вызывает MainActivity сразу после его нажатия.
public class SplashActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
}
//this method mentioned (onClick) in XML file I've not included.
public void startGame(View view)
{
Intent mainIntent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(mainIntent);
finish();
}
}
My View Class:
public class GameEngine extends View
{
boolean inGame;
//Here some code...
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
if(inGame)
{
canvas.drawBitmap(someImage, positionX, positionY, null);
if(positionX > 100)
{
inGame = false;
//Here I want to return to SplashActivity, where my ImageButton is!
}
}
}
}
Я не знаю, как реализовать идею возвращения в Activity и начать использовать мое приложение с самого начала. Заранее спасибо!
РЕДАКТИРОВАТЬ
Эта информация не относится к делу!
Innitialy Я изменил код для большей читаемости, чтобы коснуться основной точки.
Это внутренний класс, где он обновляется:
public static class Drawable
{
private int x;
private int y;
Drawable(int x, int y)
{
this.x = x;
this.y = y;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
void update() {
x -= 3;
}
}
Вот как на самом деле рисуют мои объекты
for (Drawable drawable : drawables)
{
//Draw upper pipe
canvas.drawBitmap(pipeUp, drawable.getX(), drawable.getY(), null);
//Draw lower pipe
canvas.drawBitmap(pipeBot, drawable.getX(), drawable.getY() +
pipeUp.getHeight() + GAP, null);
}
Вот как он обновляется
private void animation()
{
for(Drawable drawable : new ArrayList<>(drawables))
{
drawable.update();
if(drawable.getX() == dWidth/3 + dWidth/3)
{
drawables.add(new Drawable(pipeX, (int)(Math.random() *
(pipeUp.getHeight() -((pipeUp.getHeight() * 0.25))) - (pipeUp.getHeight() - (pipeUp.getHeight() * 0.25)))));
}
if(drawable.getX() <= 0 - pipeBot.getWidth())
{
drawables.remove(drawable);
}
}
}
Затем я вызываю animation () в методе onDraw.