By default android creating new project as ActionBarActivity - android

I recently updated eclipse, SDK and my problems are
By default it takes fragment_main.xml
Extends default activity to ActionBarActivity
By default it is adding the library appcompat 7
I dont have any issues with adding the library, but when i am trying to run then it is not executing in the device(2.3 android). I noticed it and changed to Activity.
If i extends it to Activity and run it and again for the next time the same problem arises while creating new Activity like...
Creating 2 xml files with extending ActionBarActiity.
I just want the new class to extend Activity but not ActionBarActivity where my target device is 2.3 and above without downgrading it

ActionBarActivity extends FragmentActivity and provides a nice bar(hehe) above your layout. Your editor is doing it correctly. ActionBarActivity was added in newer version of the sdk and it was added in the support library for older versions using appcompact v7(api 8). So most probably your development enviroment is correct. My guess is you need to check your imports and import ActionBarActivity from the support package.

It comes in SDK v4.4 . It is a plus point for developers because developers don't need to manually add the ActionBarActivity into their project. There are two solutions for your problem.
Downgrade your SDK to 4.3 or lower.
or
Remove ActionBarActivity and extends Activity in your java file.
Both will work for you.

Related

How to cast AppCompatActivity to Activity

I am having an activity that extends appcompatactivity I want to use the methods of activity like getwindow(), setRequestedOrientation() and finish() etc. but not able to do so... It says cannot resolve method. so, is there any way cast AppCompatActivity to Activity.
I am using Android Studio 3.0 Canary 4
For a minimum API level of 15, you'd want to use AppCompatActivity. So for example, your MainActivity would look like this:
public class MainActivity extends AppCompatActivity {
....
....
}
To use the AppCompatActivity, make sure you have the Google Support Library downloaded (you can check this in your Tools -> Android -> SDK manager). Then just include the gradle dependency in your app's gradle.build file:
compile 'com.android.support:appcompat-v7:22:2.0'
You can use this AppCompat as your main Activity, which can then be used to launch Fragments or other Activities (this depends on what kind of app you're building).
The BigNerdRanch book is a good resource, but yeah, it's outdated. Read it for general information on how Android works, but don't expect the specific classes they use to be up to date.
You can cast AppCompatActivity to Activity:
((AppCompatActivity) getActivity()).someAction...

Why does MainActivity in Android extend different activity classes at different times?

Could you please help me with this question?
When I create a new project I see MainActivity extending the Activity class or AppCompatActivity. Why does this happens? What is the reason behind changing the default settings of android project everytime? What are the other classes that MainActivity can extend? I would appreciate any help.
Actvity has support for system ActionBar which was introduced in Android 3.0 (API level 11).
AppCompatActivity has interface to work with ActionBar from support library and can be used with API Level 7).
If you want to support some features like actionbar, to lower API level of android so use AppcompateActivity.For example, if you extend youractivity with Activity class then you can not use actionbar in api level 7 because actionbar feature added in api level 11.
AppCompatActivity provide backward compatibility for new features
I see MainActivity extending the Activity class or AppCompatActivity.
Well it depends on you what type Activity you uses in your project.when you creates a new project it asks for Activitytype. like FragmentActivity etc.

Android ADT Bundle Creates appcompat and I don't what

I downloaded the ADT Bundle directly from android website for my mac. Everything was fine until I created a new project, and eclipse created my project as well as a folder named "appcompat_v7".
But I don't it, because that way I can't follow the tutorial, since you can't extend a method more than 1 time for example:
public class MainActivity extends ActionBarActivity
What can I do ? I can't follow any tutorial. I was trying this one (https://www.youtube.com/watch?v=E780gbh6vLU) and I can't because I have that appcompat_v7 project. The same happens with this one (http://code.tutsplus.com/tutorials/android-sdk-create-a-barcode-reader--mobile-17162)
Please I really need help, for my university project.
You can make it extend Activity and use the android.app.* versions of various classes (Activity, Fragment, etc) instead. IN your styles.xml, make your base style extend an Android-provided theme (like Theme.Holo) instead of the AppCompat one.

android adt bundle automatically extending ActionBarActivity and adding fragments and more stuff?

I just want to make a simple Hello world app that extends Activity but when I create a new android project it add all this extra stuff. It didn't use to do it before,but now everytime I create a project it extends ActionBarActivity and creates a fragment layout and has code for fragments and its no longer the simple project I used to be able to create.
How do I fix this?
I too had the same problem and this is how I fixed it.
When you create new Android Application Project, select Minimum Required SDK as API 14 or above.
If you want to support API level < 14 you can change the "minSdkVersion" in AndroidManifest.xml manually after creating the project.

android fragments make it work on android 2.2

I am playing around the fragments tutorial found here on section 21. It works fine when my build target is android 4.0 but when i try to change it to make it work with android 2.2, i get Error inflating class fragment on the line setContentView(R.layout.main); on MainActivity class.
I already added the support package, changed classes ListFragment and DetailFragment to extend android.support.v4.app.ListFragment and android.support.v4.app.Fragment respectively. There are no compile errors.
Did I miss something? TIA!
--EDIT---
Made it work. I changed DetailActivity.java and MainActivity.java to extend FragmentActivity instead of just Activity. Everything's okay now. But still don't know why I have to do that.
Changed DetailActivity.java and MainActivity.java to extend FragmentActivity instead of just Activity.
Using the v4 Library APIs

Categories

Resources