App closes when adding code

Asked

Viewed 18 times

0

I created a function that makes the app full screen without using XML

Only when I call this function on my second Activity, the APP closes

I use main.tela_full

package com.mugen.com;

import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.view.View.*;
import android.app.Activity;
import android.content.pm.*;
import android.text.*;
import android.content.*;
import android.util.*;

public class MainActivity extends Activity 
{
        
    Intent oi = new Intent();

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
    
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        FrameLayout layout = findViewById(R.id.main);
        FrameLayout layout2 = findViewById(R.id.tela);
    
    setContentView(R.layout.main);
    tela_cheia();
    adiciona("eu ", 0F, 0F, 0);
    adiciona("sou o ", 0F, 150F, 0);
    
    adiciona("YUKEN",  0F, 300F, 0);
    oi.setClass(this, tela2.class);
    
    
    }
    public void adiciona(String nome, float x, float y, int n){
        FrameLayout layout;
        
        
    layout = findViewById(R.id.main);
    
    //cria e edita o botao
     Button b1 = new Button(this);
     b1.setX(x);
     b1.setY(y);
        b1.setLayoutParams(new RelativeLayout.LayoutParams (ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
      b1.setText(nome);
      b1.setOnClickListener(new OnClickListener()
      {
          @Override
          public void onClick(View v)
          {  
          
          FrameLayout layout;
        
        
          layout = findViewById(R.id.main);
          alerta("foi", "oged", "#808080");
          
          startActivity(oi);
          
          
          
          
              // Toast.makeText(MainActivity.this, "foi", 2000).show();
          }
      }
      );
      
      layout.addView(b1);
      }
      
     
      
      //alerta
      public void alerta(String msg, String msg1, String msg2)
      {
         
          AlertDialog.Builder dialogo = new AlertDialog.Builder(MainActivity.this);
          dialogo.setMessage(Html.fromHtml("<font color='"+ msg2 + "'>"+ msg+ "</font>"));
          
          dialogo.setTitle(msg1);
        
          dialogo.show();
      }
      
      //tela cheia
      public void tela_cheia()
      {
          View tela = getWindow().getDecorView();
          tela.setSystemUiVisibility(
          tela.SYSTEM_UI_FLAG_IMMERSIVE_STICKY|
          tela.SYSTEM_UI_FLAG_FULLSCREEN|
          tela.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
          
      }

      @Override
      public void onWindowFocusChanged(boolean hasFocus)
      {
          // TODO: Implement this method
          super.onWindowFocusChanged(hasFocus);
        
         tela_cheia();
        
          Log.e("funcionou", "funcionou");
      }

    
      
       
       
       
  
    
}

Activity 2

package com.mugen.com;
import android.app.*;
import android.os.*;

public class tela2 extends Activity
{

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO: Implement this method
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tela_teste);
        main.tela_cheia();

    }
    MainActivity main = new MainActivity();
    
    
    @Override
    public void onWindowFocusChanged(boolean hasFocus)
    {
        // TODO: Implement this method
        super.onWindowFocusChanged(hasFocus);
        main.tela_cheia();
    }
    
    
}
  • First, what do you mean by "full screen"?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.