I just started programming android apps with eclipse..
I try to follow this guide: http://developer.android.com/training/basics/firstapp/building-ui.html
but I can't get further than here..
When I run my app through my htc phone, it just shows an empty app....
Then I tried creating a totally new android application in eclipse, and as a standard, there is an app with a text writing "Hello world"..
And when I show my activity_main.xml in graphical layout, it shows an app with this text "hello world".... but still, when I run it through my htc, I still just get an empty app...
How can this be, what am I missing?
Thanks.
Edit: actually, the app on the phone is not totally empty... it does show the standard head-banner with the android logo and the name of my app. But no textview...
First close the version of application that is already running on the HTC device. OR best thing woulld be uninstall it and try again.
It should work
Also, set the content view
setContView(R.layout.your XML file name);
Your activity does not add any content to the window so therefore nothing is shown.
Seems like you already have the wizard-generated layouts in res/layout. Just add
setContentView(R.layout.activity_main);
to onCreate() where activity_main corresponds to res/layout/activity_main.xml and that layout file actually contains the UI you want displayed.
Also import your generated resource identifiers:
import com.example.nytapp.R;
You will also need to call the superclass onCreate() in your onCreate(). Add
super.onCreate(savedInstanceState);
as the first line in your onCreate().
The warning
ActivityManager: Warning: Activity not started, its current task has been brought to the front
is nothing to worry about - if you didn't change your code and try to run it, the app won't get reinstalled and launched but just an existing instance is brought to front.
Related
I have a little problem. I have a Bluetooht activity which contains two fragment. The goal of the first fragments is to know if the bluetooht is activated on the phone (Nothing complicated).
To do something clean I would like to update my fragment when the user opens the phone taskbar since he can activate bluetooht.
The problem is, I can't find the methods to call when opening or closing the taskbar.
I have already tried onResume but obviously it is not calling.
Does anyone have an idea?
thank you in advance
I was writing an app and I was in main activity (had written thousands of lines of codes). But when I wanted to shut down my laptop, it took a while so I had to push the power button to force a shut down. Then after a while, when I powered on my laptop again and opened Android Studio, all my main activity code was gone! It's so weird.
I can see in project folder that main activity has about 40kb size but it's all empty. So is there something wrong with Android Studio and can I fix it? If not, can I use some tools or tricks to get another version of my main activity file (like changing the last date modified to the one before it or something like that).
Try to right click on your MainActivity and choose Local History > Show history
Check if it is in your android studio history .
I have a problem with android studio emulator. Every time I create my own activity, for example myscreen.xml, and in MainActivity.java I change this line of code
setContentView(R.layout.activity_main) into setContentView(R.layout.myscreen);
the emulator shows me the following error: "UNFORTUNATELY LAUNCHER HAS STOPPED TO WORK". But if I use my main activity, for example setContentView(R.layout.activity_main);, it works perfectly without an error.
I tried everything on Virtual Device: changing the ram size, VM heap, internal storage, SD card. Nothing works. How do I fix this?
As long as the layout of myscreen.xml is valid and it is contained within the app/res/layout/* folder the myscreen.xml layout should work.
If you would like further help, it would be useful to see both the activity.java in which the layout is being used and the myscreen.xml file.
I'am new here > i want some help to build some code but i can't find any code ..>
i have some project i must done it > so i hear about this website which is giving us helps by professional developer and programmer .My Question :how i can show my layout(xml file) when i open any android app ?? >> i mean how i can call my activity when i open any android application or replace activities between my app and any apps in android device.... so when i open any android application in my device the result will be show my layout(xml file) ... so how i can do it ??
i wish that anyone answer me ....
and i will be thankful
I'am called : (amjad)
Actually assuming you have 1 activity name as MainActivity in src folder of eclipse
and xml file name as main in res->layout
then you have to add following code in your activity
setContentView(R.layout.main);
By this you can use contain in xml file
dude check this guy :) he has a beginners tutorial series with index, so you can check any certain topic ,or follow one after another to save you time in learning best of luck ;)
http://www.vogella.com/articles/Android/article.html
Please refer to below link (basic tutorial for Android from Android/Google team):
http://developer.android.com/training/basics/firstapp/building-ui.html
Update:
I see that you have edited the question with more details. But, I am not sure if there is a way to call your app automatically when some one starts another App in the device unless it's a system level app. What you can do is provide one public intent to be called by any other apps and then at load time, the app calls your intent and hence can display your layout/xml.
I've used this file list for my new Android app:
http://android-er.blogspot.com/2010/01/implement-simple-file-explorer-in.html
But the problem is that after I've browsed through the folders and then pressing the back-button of my phone, the app is closing instead of going to the previous folder.
(because it's still on the same activity, only some variables are changed)
Is there a possibility to fix this file browser that I can use the back-button without creating multiple activities?
Thank you!
You can override onBackPressed in your activity and do whatever you need there to go to a previous directory.