Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从特定活动返回后在其他元素上绘制的SurfaceView_Java_Android_Api - Fatal编程技术网

Java 从特定活动返回后在其他元素上绘制的SurfaceView

Java 从特定活动返回后在其他元素上绘制的SurfaceView,java,android,api,Java,Android,Api,我有一个活动,通过SurfaceView和其他视图显示视频预览。问题在于,当用户导航到“设置”活动(下面的代码)并返回时,会在所有其他活动的顶部绘制surfaceview。当用户转到我拥有的另一个活动时,也不会发生这种情况,当用户导航到应用程序之外(例如任务管理器)时也不会发生这种情况 现在,您可以在下面的代码中看到,我已将setContentVIew()调用包装在条件中,因此不会在每次执行onStart()时调用它。如果它没有封装在If语句中,那么一切都可以正常工作,但是每次调用onStart

我有一个活动,通过SurfaceView和其他视图显示视频预览。问题在于,当用户导航到“设置”活动(下面的代码)并返回时,会在所有其他活动的顶部绘制surfaceview。当用户转到我拥有的另一个活动时,也不会发生这种情况,当用户导航到应用程序之外(例如任务管理器)时也不会发生这种情况

现在,您可以在下面的代码中看到,我已将setContentVIew()调用包装在条件中,因此不会在每次执行onStart()时调用它。如果它没有封装在If语句中,那么一切都可以正常工作,但是每次调用onStart()时都会导致大量内存(5MB+)丢失。我尝试了各种组合,但似乎没有任何效果,因此任何帮助都将不胜感激

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    //Toast.makeText(this,"Create ", 2000).show();
    // set 32 bit window (draw correctly transparent images)
    getWindow().getAttributes().format = android.graphics.PixelFormat.RGBA_8888;

    // set the layout of the screen based on preferences of the user

    sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
}


public void onStart()
{
    super.onStart();


    String syncConnPref = null;
    syncConnPref = sharedPref.getString("screensLayouts", "default");

    if(syncConnPref.contentEquals("default") && currentlLayout!="default")
    {
        setContentView(R.layout.fight_recorder_default);    
    } 
    else if(syncConnPref.contentEquals("simple") && currentlLayout!="simple")
    {
        setContentView(R.layout.fight_recorder_simple);
    } 

            // I I uncomment line below so it will be called every time without conditionals above, it works fine but every time onStart() is called I'm losing 5+ MB memory (memory leak?). The preview however shows under the other elements exactly as I need memory leak makes it unusable after few times though

            // setContentView(R.layout.fight_recorder_default);

    if(getCamera()==null)
    {
        Toast.makeText(this,"Sorry, camera is not available and fight recording will not be permanently stored",2000).show();

        // TODO also in here put some code replacing the background with something nice

        return;
    }

    // now we have camera ready and we need surface to display picture from camera on so
    // we instantiate CameraPreviw object which is simply surfaceView containing holder object.
    // holder object is the surface where the image will be drawn onto 
    // this is where camera live cameraPreview will be displayed

    cameraPreviewLayout = (FrameLayout) findViewById(id.camera_preview);

    cameraPreview = new CameraPreview(this);

    // now we add surface view to layout

    cameraPreviewLayout.removeAllViews();

    cameraPreviewLayout.addView(cameraPreview);

    // get layouts prepared for different elements (views)

    // this is whole recording screen, as big as screen available

    recordingScreenLayout=(FrameLayout) findViewById(R.id.recording_screen);

    // this is used to display sores as they are added, it displays like a path
    // each score added is a new text view simply and as user undos these are removed one by one

    allScoresLayout=(LinearLayout) findViewById(R.id.all_scores);

    // layout prepared for controls like record/stop buttons etc

startStopLayout=(RelativeLayout) findViewById(R.id.start_stop_layout);      

    // set up timer so it can be turned on when needed

    //fightTimer=new FightTimer(this);

    fightTimer = (FightTimer) findViewById(id.fight_timer);

    // get views for displaying scores

    score1=(TextView) findViewById(id.score1);
    score2=(TextView) findViewById(id.score2);
    advantages1=(TextView) findViewById(id.advantages1);
    advantages2=(TextView) findViewById(id.advantages2);
    penalties1=(TextView) findViewById(id.penalties1);
    penalties2=(TextView) findViewById(id.penalties2);
    RelativeLayout welcomeScreen=(RelativeLayout) findViewById(id.welcome_screen);

    Animation fadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    welcomeScreen.startAnimation(fadeIn);

    Toast.makeText(this,"Start ", 2000).show();

    animateViews();         
}
“设置”活动位于下方,从该活动返回后,将在其他元素的上方绘制surfaceview

public class SettingsActivity extends PreferenceActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if(MyFirstAppActivity.getCamera()==null)
        {
            Toast.makeText(this,"Sorry, camera is not available",2000).show();
            return;
        }

        addPreferencesFromResource(R.xml.preferences);

        }
}