1

So I want to make those 3 lines to be available as a function from every activity in my app. I tried to do a simple MyMethods class with a public void with those 3 lines, but i didn't work (Cannot resolve method )

package com.example.myapplication;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

public static final String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

@Override
protected void onCreate(Bundle savedInstanceState) {

    //landscape,fullscreen,no action bar

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    //I want those 3 lines above to be one void function 

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


}


public void sendMessage(View view){
    Intent intent = new Intent(this, DisplayMessageActivity.class);
    EditText editText = (EditText) findViewById(R.id.editText);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}

}

Paweł Rubin
  • 2,030
  • 1
  • 14
  • 25

2 Answers2

1

Try this way,

 public class MyMethods extends AppCompatActivity  
 {
    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        super.onCreate(savedInstanceState); 

    }

  }

Now extends this in your MainActivity class

public class MainActivity extends MyMethods {
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

If you are doing it by java code, that is not recomended. Bettwer way to make your activity full screen is to do it via activity theme.

<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

And give this to your every activity those you want to make full screen.

<activity
   android:name=".activities.MyFullScreenActivity"
   android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen" 
/>

Hope it will work ... :)

Neo
  • 3,546
  • 1
  • 24
  • 31