I am new to android i made a project but every I create a project class it extends actionbaractivity always created, instead of extends activity before it was extends activity every time I created a class, maybe i press something But i dont really know what happned.
This is the result and actionbarActivity is error
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
If you set up your project to target API < 11 there will be checkboxes for certain support features. ActionBar, GridLayout, Fragments, and NavDrawer. If you check ActionBar the activity that is generated will extend ActionBarActivity (which is the support version of a fragment activity) It may be confusing at first but it's all in the name of supporting older versions of Android with the latest features.
http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html
If you set your minimum required SDK below 11 it will create the application like this because in API level below 11 there is no ActionBar. The default value is 8. You should set it 14 and then you can change it in your AndroidManifest.xml file.
Related
Ok here is the issue, the native Android Fragment is deprecated.
This will be use in an Unity Android native plugin.
In the old ways you simply create a Fragment class like this:
public class UnityAndroidNativeplugin extends Fragment
{
public static void Init()
{
instance = new UnityAndroidNativePlugin
UnityPlayer.currentActivity.
getFragmentManager().
beginTransaction().add(instance, UnityAndroidNativeplugin.LOG_TAG).commit();
}
}
That works fine but I still don't get, if this is deprecated we should use the support fragment library. Ok I will update this.
So when I change to the new version it should be something like this.
public class UnityAndroidNativeplugin extends android.support.v4.app.Fragment
{
public static void Init()
{
instance = new UnityAndroidNativePlugin
FragmentManager fragMan = UnityPlayer.currentActivity.getSupportFragmentManager();
//This Fails
}
}
I already know that my main Activity should be a FragmentActivity.
Cannot call getSupportFragmentManager() from activity Check here.
So it's not possible to use android.support.v4.app.FragmentManager while using Android Activity (android.app.Activity)?
One solution is to override the Unity Main activity but that could have problems when using other plugins. Or maybe using something else than a fragment.
So it's not possible to use android.support.v4.app.FragmentManager while using Android Activity (android.app.Activity)
Correct.
if this is deprecated we should use the support fragment library
Or, better yet, the AndroidX one, as the Support Library one will become obsolete before long.
this thread says :
FragmentActivity is for use with the backport of fragments found in
the support-v4 and support-v13 libraries. The native implementation of
fragments was added in API Level 11
I am using a min sdk of level 15 and I was only able to make the import of fragment work with FragmentActivity and getSupportFragmentManager, instead of extending Activity or AppCompatActivity and using getFragmentManager :
public class MainActivity extends FragmentActivity implements TaskFragment.OnFragmentInteractionListener {
private TaskFragment mTaskFragment;
private static final String TAG_TASK_FRAGMENT = "task_fragment";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
Would someone know why, and have some details about the sdk levels that should be used with v4 or v7, or v13(?)
Thanks
You should extend you activity from AppCompatActivity and use getSupportFragmentManager.
I don't know what TaskFragment is – something third party I presume.
Remember to add the Google Android support library com.android.support:appcompat to your project.
I've seriously tried everything.
I've tried both setLogo() and setIcon().
I've tried adding android:logo="" in manifest.
I've made sure to try both supportActionBar and regular ActionBar. (I'm running sdk 21 with a min sdk of 15.)
The funny thing is if I try to use the regular ActionBar I get null pointers but when I use the support ActionBar it at least works.
Is there anything else I can try...? Here's where I try and change it.
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar ab = getSupportActionBar();
ab.setLogo(R.drawable.logo);
If your min sdk is 15, i'm not sure why you're using the support package at all.
You class should instead extend Activity, and use getActionBar().
I am a newbie to android and I was following the tutorial on android.developer.com,Where a new Activity creation adds an activity which extends ActionBarActivity by default,but When i
create a new Activity it extends Activity class by default
I have also tried to set the Min API to 4.1 Jelly Bean and target to 4.4 as ActionBarActivity is available in later API but it didn't work,I have downloaded the Adt bundle from the site
When you create new project in eclipse, you should select min required SDK below 14 to extend from ActionBarActivity.
Check this: android adt bundle automatically extending ActionBarActivity and adding fragments and more stuff?
I'm having problem with ActionBar Sherlock (latest version), after successful compilation I don't see ActionBar in app. Just black screen and default TextView...
Before I've a problem with install libraries, but after added Support Library to ActionBarSherlock I can built it.
import com.actionbarsherlock.app.SherlockActivity;
public class MainActivity extends SherlockActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Manifest:
android:theme="#style/Theme.Sherlock"
Make sure your android:targetSdkVersion is set to 11 or higher in your manifest.