I am really confused right now because whenever I create a new Android app with blank activity it always comes out with fragment_main.xml. I just wanted to create a blank activity without the fragment one.
In the first image the blank activity comes with the fragment layout:
The second image shows the created fragment_main
Now I am really confused... this only happened after updating ADT to the latest version.
I have referred to this thread: Adt doesn't create default hello world but command line does_
I just wanted to make an Android app with blank activity with no fragment view.
For those who would like instructions on how to remove Fragments from the project:
1) Copy all the contents of res/layout/fragment_main.xml. Open activity_main.xml, delete the FrameLayout, and paste in the copied contents.
2) Delete fragment_main.xml
3) In MainActivity.java, delete the whole PlaceHolderFragment class:
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main,
container, false);
return rootView;
}
}
4) Delete the following lines from onCreate():
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
At this point you should be all set to run the project.
You can use the previous template by editing the template files inside the Android SDK folder. But, make sure you have a backup of the "BlankActivity" folder.
Go to /templates/tools/templates/activities/BlankActivity
Locate the template.xml file and locate the following piece of code
<parameter
id="fragmentLayoutName"
name="Fragment Layout Name"
type="string"
constraints="layout|unique|nonempty"
suggest="fragment_${classToResource(activityClass)}"
default="fragment_main"
help="The name of the layout to create for the activity's content fragment" />
and change the constraints to constraints="empty".
Locate recipie.xml.ftl and locate the following piece of code
<instantiate from="res/layout/fragment_simple.xml.ftl"
to="${escapeXmlAttribute(resOut)}/layout/${fragmentLayoutName}.xml" />
and comment the whole line.
Locate SampleActivity.java.ftl file inside root/src/app_package and delete these two lines
<#include "include_options_menu.java.ftl">
<#include "include_fragment.java.ftl">
Locate fragment_simple.xml.ftl and activity_fragment_container.xml.ftl file inside root/res/layout. Copy the contents of fragment_simple.xml.ftl file to activity_fragment_container.xml.ftl file.
Now when you try to create a new activity, you'll get this screen
You can leave the Fragment Layout Name field blank.
This works fine for me in the case of blank activity. I'm not sure if this is the right approach, with discarding fragments and all, but this works for me.
This is a new feature of ADT version 22.6.0:
http://developer.android.com/tools/sdk/eclipse-adt.html
Edit: With the latest ADT updates there is a new template called "Empty Activity" that has no fragments. it's a plain class that extends Activity (Even without the default menu).
Notice that there is also a "Blank Activity" which extends ActionBarActivity and has fragments
Thank you to the person that reported this, https://code.google.com/p/android/issues/detail?id=67513
This was my first glimpse into android-review.googlesource.com. Digging around I didn’t see a way to download the patch set that was put together and I’m unsure how to “cherry pick” tools_r22.6, If there's a thread that explains it a link would be appreciated.
Here’s how I went about it.
On your machine navigate to your SDK folder then \tools\templates\activities
Copy the BlankActivities folder and paste it into the same directory.
Rename BlankActivities_copy to EmptyActivities
Go to https://android-review.googlesource.com/#/c/88890/4
Under the Files section there is a list of links. Each link directs you to the xml that needs to be added to the new EmptyActivities folder you created.
Copy the xml from the right pane to the path\file at the top of the left pane(the link was also the path). If the file already exists delete the contents and replace. If the file doesn’t exist, create it and copy the xml into the file.
Repeat for each of the links.
Close and reopen Eclipse. If you have any of the files open in an editor Eclipse will crash.
Thank you to Josiah Gaskin at google with the unbelievable 2 day turnaround!
No training literature references the fragments in the BlankActivity. I’m sure this fix saved me countless hours trying to figure out how to navigate around fragments while trying to learn a new IDE.
Thanks again.
If you download the latest ADT 22.6.3 (with build tools 19.0.3) you will have the option to create a new Empty Activity that doesn't use fragments
I have also faced the same issue.
I just deleted the eclipse and again downloaded the ADT bundle from http://developer.android.com/sdk/index.html#download
To recover your previous projects, just change the work-space to your previous one.
This worked for me.
If you don't want the fragment part to be in your app then simply "unckeck the create activity option at project setup wizard, then
manually create the activity and layout" for your project.
A solution to this, is a copy of the older "Blank Activity" in %Wherever your ADT bundle is%\sdk\tools\templates\activities\.
If someone has an older version of it, you can rename it, place it in here %Wherever your ADT bundle is%\sdk\tools\templates\activities\ and then when starting your project, select this folder instead of "Blank Activity", so if you have a copy please share.
We found a solution to this:
When you create a project select "empty" activity. Then it create a MainActivity class that extends Activity and an activity_main.xml layout.
In other words, it give you the behavior that was there before.
This worked in ADT 22.6.3.
While creating a new Application,
just copy the Layout Name to the Fragment Layout Name (e.g. activity_main)
Voila!!!
You get an activity without the fragment part.
Remove this portion of the code from activity:
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
Clean the project.
A blank activity really should be more simple than this.
It appears that a fix is currently pending:
https://code.google.com/p/android/issues/detail?id=67513&q=blank%20activity&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars
You can skip the create activity option when you create your project and add in an activity manually.
If you find it really really annoying you can try rolling back ADT and the SDK:
Download the 22.3 sdk tools from: dl-ssl.google.com/android/repository/##Your platform's version of the sdk here##
For example osx is tools_r22.3-macosx.zip
Unzipping that file will give you a folder called "tools" Use this to replace the folder of the same name found in /path-to-your-android- installation/android-sdk-macosx/
Next you need to uninstall your eclipse adt plugin. Go to help -> install new software Click the link to see what's installed already Select all of the android packages and click uninstall. Restart Eclipse
Download the 22.3 ADT plugin from: http://dl.google.com/android/ADT-22.3.0.zip Unzip this file
Back in eclipse click help -> install new software Click add and select the local file you just unzipped Check what you want to install and click install Restart eclipse again
I done it by replacing the BlankActivity(22.6.2) folder to the older sdk BlankActivity(22.6.1) present in the tools/templates directory in android-sdk.
Not sure if this works completely,
Steps
1) Right click on your project goto properties->Android, remove reference library and press apply.
now you would see errors in your project go to res->values->styles, replace AppBasetheme's parent by parent="android:Theme.Light"
do this for all values folder except in values_v14 there put parent="android:Theme.Holo.Light.DarkActionBar"
2) Now goto MainActivity replace "extends ActionBarActivity" by "extends Activity". Eclipse will prompt you to import for activity do it.
now delete this part of code
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
from activity class
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
Now remove all unused imports.
3) Goto res->Layouts->fragment.xml, copy code of fragment into activity_main.xml.
Delete fragment.xml.
Now goto main.xml
Replace this
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
app:showAsAction="never"/>
by
<item
android:id="#+id/action_settings"
android:orderInCategory="100"
android:title="#string/action_settings"
android:showAsAction="never"/>
4) Now Click on Project and clean your project
For small projects, create a project without an activity and add/edit activities, layouts, and manifest manually.
Android heard our voice :).
Just upgrade or download ADT version to 23.0.2 or higher.
Now you can choose blank activity like this,
Related
I have just installed Android Studio on my pc, but I am not able to find any activity or layout file on a creation of a new project.
Here is the screen shot
From the screen-shot it is clear that you haven't created any project yet. Go to file - Click on : New - Click on : New Project.
Now create a project which will get you all the necessary elements like activities, layouts, gradle, etc.
Happy coding.
This is my first Xamarin app. I have my environment set up in Visual Studio, and have a template project which I can run in the Android emulator.
Having dragged and dropped a couple of controls on to the designer surface, I find that when I run the application in the emulator, neither of the two controls that I have added (a button and a switch) display in the emulator.
I have tried:
Cleaning the solution
Rebuilding the solution
Manually deleting bin and object files
Unchecking 'Use Fast Deployment' in project Android Options
Uninstalling from the emulator
But with the same result each time.
[Project files removed]
Am I missing something?
Just downloaded your code and ran it. Uncommenting SetContentView (Resource.Layout.Main); it worked to me.
[Activity(Label = "Tgo.AndroidApp", MainLauncher = true, Icon = "#drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
}
}
Here a nice guide to get you started with Xamarin Android.
navigate to MainActivity.cs and uncomment this code
SetContentView (Resource.Layout.Main);
and rebuild the solution and debug.
Let me know it if helps!
In my case, I had to update my Main.xml file with the updates I put into the Main.axml and Rebuild.
I am trying to following the Building Your First App from the Android developers site, and I'm stuck on the Lesson: Starting Another Activity
I downloaded and installed Eclipse SDK and the ADT plugin and that is what I am using.
I am hung up on the step on the page at the above link on the step where it says:
Open the MainActivity class and add the corresponding method:
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
}
Tip: In Eclipse, press Ctrl + Shift + O to import missing classes (Cmd + Shift + O on Mac).
I do not know what file I should open. I am using Windows, so I tried pressing CTRL + Shift + O and nothing happened. I tried looking for *.class files and could not find one. The only class file that I see is classes.dex and I don't think that is it. Can someone please point me in the right direction?
I too had this problem and spent over an hour searching for the remedy. Which I found herewith:
Go to left navigation bar and go to /src/com.example/MainActivity.java
Double click MainActivity.Java
File opens up in main window, OK, before the last "}", insert your code
yellow lines appear (indicating some sort of error!)
to resolve this, hover the mouse over the yellow lines and you will see a popup. click the option that includes "import view".
You can now continue with the tutorial...
edit:typo
Just had the same problem:
in the package explorer the file is under src\com.example.my.first.app\MainActivity.java
the com.example.my.first.app is what i got there. if you named the project differently it should reflect that.
Hope this helps!
Look under the file heading src under MyFirstApp near the very top of the package explorer on the left side of the Eclipse screen. Then look open the com.example.MyFirstApp folder and there it is. Open it and start editing.
stucked there too, but this answer helped alot. Don't forget to add "import android.view.View;" othwerwise you will get a "View cannot be resolveds to a type"-Message.
write this on button onclick()
Intent myIntent = new Intent(CurrentActivity.this, NextActivity.class);
CurrentActivity.this.startActivity(myIntent);
To pass info just use
myIntent.putExtra("key", value);
can be retrieved on the other side via
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String value = intent.getStringExtra("key");
Don't forget to add your new activity in the AndroidManifest.xml:
<activity android:label="#string/app_name" android:name="NextActivity"/>
If you checked every folder/package under /src/ in the Package Explorer on the left side but you are sure there is none, this is what helped me continue the tutorial without starting over:
I got stuck there too, because the only MainActivity.java file was at /gen/... and not /src/..., but I fixed it with deleting that exisiting one and creating a new one at /src/com.example.whatever/. Just New > Class, Name MainActivity and paste the following code:
package com.example.androidtest;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
..and now you have your MainActivity.java and can go on! (You can create a new Android Project and copy&paste the MainActivity to your existing project. You just have to adjust the )
In case this didn't help it might be, that you never had a MainActivity class in the first place. To fix this, click on New > Android > Android Activity, choose Blank Activity and enter MainActivity as name in the next panel. I tried this first but got an error, that the layout name "activity_main" already exists.
Good luck!
I'm coding in Flutter in Android Studio.
I found the file MainActivity.java with double shift key. The path is:
android\app\src\main\kotlin\com.example\MainActivity
I'm having trouble getting Eclipse to see that I've just put a new image into my project when referencing that image using R.drawable.this_text
So I drag my png into myProject/res/drawable-hdpi in Eclipse's Project Explorer. The name of the image is this_text and it's a png!
So I go into my application and I want to put this on the screen; So here's the code for that...
private void setTitle()
{
ImageView title = new ImageView(this); //this extends activity
title.setBackgroundResource(R.drawable.this_text);
...
}
This I have done before and each time I do it I experience the same thing:
if i just dragged my this_text.png into the Project Explorer in eclipse, the word "this_text" will be underlined in red, and not allow me to compile or proceed. I try to F5 (refresh) the project. I try refreshing the image foldr, the src, the actual java...etc! I try closing and opening eclipse but nothing really works. So I quit for afew minutes and work elsewhere in my application, and eventually this error goes away!
Well I'm impatient today-- And I'd rather know how to solve this incase I need to do any quick programming! So does anyone know what to do?
I'm using eclipse Version: Indigo Service Release 1.
Thanks- Ethan
R files for android are generated. Rather than refreshing you should be able to CLEAN the project which should fix your issue. You could even just delete the error from the problems list which would allow for compilation to start and for the generated R file to be created. Or you could make a change to an xml which would also allow for the file to be regened. As always make sure you are up to date on your tool chain.
I'm trying to use PhoneGap with Android. In the Sample that I run the main app opens an html file:
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
super.loadUrl("file:///android_asset/www/index.html");
}
Now if I change something in the html page, Android always shows the previous content.
Is it possible that the output files (resources in that case) are not updated?
Also if I change the name of the html file in /assets/newName.html and into .loadUrl nothing changes.
Thank you, F.
I'm determined to find a proper answer to this, at the moment changes in the assets dir do not trigger a rebuild.
At the moment I'm slapping a new line in the Activity.java code to force a rebild/deploy..
Will update once I've looked for a real solution.
I see this sometimes when I add a data file to a project in eclipse.
If you think you pkg isnt being updated (re-built) then just rebuild it manually. If your using eclipse just do project->clean and select the project you want to clean. it'll rebuild automatically and include anything that was missed out.
OK Guys found.
The tutorial in the wiki.phonegap.com is obsolete.
Samples instead are updated!
Many thanks.