Android Studio creating new activity has no "Blank activity" choice - android

Each time I tried to create new phone project with AS and adding new activity (as show in the illu) I can not see "Blank activity" in the menu of items.

There is simply no Blank Activity. Android Studio change the Blank Activity into Basic Activity

Select java class and extend AppCompatActivity:
public class MainActivity extends AppCompatActivity {
// set here your layout by using setContentView
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Related

How to prevent the Screentshot in the entire android app without repeating the same code

Hi everyone i want to block the Screenshot in my app. I got the first problem solve from here.
But now the thing is I have more than 10 activity and 10 + fragment.
Is there any way to do this just by writing in the one class and giving it reference to the entire app.
Just like we make one Application class and in the AndroidMainfest.xml give that application class refrence.
You can implement a BaseActivity, and make all your activities extend this BaseActivity. In onCreate() of this activity set the flag. You need to ensure all your activities call super.onCreate() as follows:
BaseActivity.java
public abstract class BaseActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//set your flag here
...
}
}
Activity1.java
public class Activity1 extends BaseActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
}
}

INTENT and SETTINGS activity giving Cannot Resolve Contructor error

Working on my first Android project and needed to add a settings activity for program settings. I created a MainActivity with a single button to test the settings activity.
I created the default SettingsActivity from Android Studio (didn't change anything).
Tried calling the Settings Activity via a click on the button from the main activity. Getting the following error:
Cannot Resolve Constructor 'Intent(android.view.View.OnClickListener...
The Settings Activity is called ProgramSettingsActivity and is the default code that AndroidStudio creates... for now. The beginning of it reads...
public class ProgramSettingsActivity extends PreferenceActivity {
private static final boolean ALWAYS_SIMPLE_PREFS = false;
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
setupSimplePreferencesScreen();
}
...
The code in the mainActivity is as follows:
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button=(Button)findViewById(R.id.myButton);
button.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
Intent i = new Intent(this,ProgramSettingsActivity.class);
startActivity(i);
}
});
}
...
Not sure where to go from here... I am obviously missing something obvious.
Thanks for any help....
Use Intent i = new Intent(MainActivity.this,ProgramSettingsActivity.class);
Inside anonymous class new Button.OnClickListener(){} this refers to the instance of this class, not its enclosing MainActivity class. That's how it happens.

how to create custom listadapter class in android studio

i switched eclipse to android studio i m little bit confuse on working android studio and i was working on listview app but custom adapter class not inherit to parent class .
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView)findViewById(R.id.listView);
custom cos=new custom(this);
lv.setAdapter(cos);
}
..but custom name java class not inherit to parent class in android studio.
Make use of
public class YourClassName extends BaseAdapter{
.... its method
}

Layout cannot be removed

I am trying to remove the layout when the apps starts.
I removed "setContentView" from the MainActivity.java file but still the layout is showing when the activty starts..
How can I remove the layout??
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setVisible(false);
}
}
try adding this to your manifest, inside activity android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen"

Android app : show PreferenceFragment as a dialog?

I'm new to Android (with iOS background) and I would like to do the following :
I've made a PreferenceFragment in which I ask the user his credentials to connect to my WebServices. When I detect that those credentials are rejected by my server, I would like to show to my user a dialog (modal) where he can edit his preferences (credentials).
I've manage to do it using PreferenceActivity. So when I click a bouton, I execute the following code :
Intent settingsActivity = new Intent(getActivity().getBaseContext(), PreferencesConnection.class);
startActivity(settingsActivity);
Which load a PreferenceActivity as a Dialog with an XML ressource :
addPreferencesFromResource(R.xml.preferences_connection);
But this is depreciated. I can I do the same, but with Fragment? Should I use DialogFragment to show my PreferenceFragment, or not? Would it be easier to just rebuilt my credentials in a DialogFragment? Should I use a Activity instead of Fragment?
To do an old fashioned, single page settings screen without PreferenceHeaders, do as follows:
In your activity that invokes the settings screen (example is in onMenuItemSelected):
case R.id.menuSettings:
Intent settingsIntent = new Intent(this, SettingsActivity.class);
startActivityForResult(settingsIntent, GC.SETTINGS_ACTIVITY_ID);
break;
In your XML folder, create an old fashioned PreferenceScreen. PreferenceCategory, ListPreference, CheckBoxPreference, etc. Do not use PreferenceHeaders
Create a settings activity:
package com.mycompany.project1;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
public class SettingsActivity extends PreferenceActivity {
private final static String TAG = "SettingsAcitivity";
public SettingsActivity() {}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyLog.d(TAG, "onCreate");
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new LocationFragment()).commit();
}
public static class LocationFragment extends PreferenceFragment {
private String TAG = "LocationFragment";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MyLog.d(TAG, "onCreate");
addPreferencesFromResource(R.xml.settings);
}
}
}
Do not associate a dialog theme with the settings activity. You will get weird results for certain preference types such as radio buttons. (I tried the dialog thing and couldn't find the coding error(s). Everything worked fine when I used the standard activity theme instead of the dialog theme. Evidently the holo dialog theme collides with settings definitions.
Note: I used startActivityforResult so I could reinitialize specific settings values that changed.

Categories

Resources