android平板电脑中的备用操作

android平板电脑中的备用操作,android,Android,我尝试过这样做。当安卓平板电脑中的任何人在5分钟后不触摸屏幕时,我想在屏幕上显示一张照片,直到有人触摸屏幕为止。我如何做到这一点。我开发了一个安卓应用程序,我需要在我的应用程序中添加此功能。正确的方法是创建一个独立的活动仅包含要显示的图像,如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

我尝试过这样做。当安卓平板电脑中的任何人在5分钟后不触摸屏幕时,我想在屏幕上显示一张照片,直到有人触摸屏幕为止。我如何做到这一点。我开发了一个安卓应用程序,我需要在我的应用程序中添加此功能。

正确的方法是创建一个独立的活动仅包含要显示的图像,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/YOUR_IMAGE"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</LinearLayout>
@Override 
    public boolean onTouchEvent(MotionEvent event) {
        x = 0;
        return true;
    }
@Override 
    public boolean onTouchEvent(MotionEvent event) {
        YOUR_ACTIVITY.x = 0;
        Intent intent = new Intent(getApplicationContext(),
                    YOUR_ACTIVITY.class);
            intent.putExtra(EXIT, false);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
    }
然后用以下内容覆盖该活动的
onTouchEvent

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/YOUR_IMAGE"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</LinearLayout>
@Override 
    public boolean onTouchEvent(MotionEvent event) {
        x = 0;
        return true;
    }
@Override 
    public boolean onTouchEvent(MotionEvent event) {
        YOUR_ACTIVITY.x = 0;
        Intent intent = new Intent(getApplicationContext(),
                    YOUR_ACTIVITY.class);
            intent.putExtra(EXIT, false);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
    }
然后覆盖
图像
活动的
onTouchEvent
,以便当有人触摸它时,它会运行
您的_活动
活动,并将
x
设置为0

要从
图像
活动返回
您的\u活动
,请覆盖
图像
活动中的
onTouchEvent
方法,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/YOUR_IMAGE"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</LinearLayout>
@Override 
    public boolean onTouchEvent(MotionEvent event) {
        x = 0;
        return true;
    }
@Override 
    public boolean onTouchEvent(MotionEvent event) {
        YOUR_ACTIVITY.x = 0;
        Intent intent = new Intent(getApplicationContext(),
                    YOUR_ACTIVITY.class);
            intent.putExtra(EXIT, false);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
    }

我尝试过这个,但它不起作用。我创建了另一个类,它的名称是Image,我是onTouchEvent,但它不起作用。你能用
setContentView(R.layout.Image\u layout)编写你分配给它的
onCreate()
图像类吗?谢谢,它可以工作,但当它转到图像活动时,我想回到(您的活动)类中,我再次尝试使用此方法中的onTouchEvent(MotionEvent)方法和Intent,但每次加载图像活动时,它都不返回原因???@Rıdvan在回答的末尾查看我的新更新