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 .
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 am working on a minimal open-source Launcher (wikipedia) for Android.
When I run it on a phone, put that on standby and unlock it after 4 - 6 hours, all I get is a black screen.
I hope this has some general solution and is not only caused by my code.
That way answers to this question will also be useful to everyone else on here.
Relevant mentions for my code
In the Android Manifest XML I declared the main activity to be a launcher (home screen). The main activity (MainActivity.kt) has an onCreate function, only refreshes a clock and checks for some OnTouch events. The full project code can also be seen on GitHub.
Go to the related issue on Github.
You should try implementing onResume() if you haven't already. It is possible that the app has not stopped and as such onStart() would not be called when you unlock your phone.
Where an app has paused, it would just call onResume() instead. You can try putting your code here to recreate the views as needed. You can also save any relevant user information in onPause() and reload it in onResume(). This will allow you to preserve a consistent user experience and avoid memory leaks caused by, for example, referring to objects that no longer exist.
Let me know if it works, good luck.
The Activity Lifecycle
i am working on a clock box app that contain several clock widgets the reason i want to put clocks in an another apk is its 30 clock for god sake its gets my phone widget manager force stop if i put all the clock codes in one apk. so i made 30 seperate clocks and now i stucked at the end how can i open them with package installer using intent?
the clocks are in assets folder and i just want to open them with package installer.
can any body teach me how to do it?
i am still learning so if you give me the whole code it would be great!
(my clint gets 403 so i cannat use google library)
So I have a project done which I made in Eclipse, I have also exported it as a Android and somehow imported it in Android Studio, But when I run the program in Android studio, it will execute as Java. And what I want to do is to make it execute in a Android phone (Can also be in a simulator)
But I have not found any tutorials on how to do it and I really need to do it since the essay is ending soon. So I would appreciate all help!
If more info needed, Please, Just comment. I will be available here next 2 hours!
The process should be quite simple if you have already succeeded in importing the project into Android Studio.
If you are using a Mac the process is very simple. If you are using Windows then there is one additional step described below:
In the AndroidManifest.xml make sure you have android:debuggable="true.
If you are using an Android phone with API 4.0+ then go into the phone's Settings and click on About Phone seven times. This might seem like a strange thing to do but it unlocks the phone's developer options, which are hidden by default. On older phones just go to Settings -> Applications -> Development.
In the Developer options select to allow USB debugging.
Now, connect the phone to the computer using a USB cable. You will probably see a message on the phone asking you to authorise the computer for that phone.
Next, open Android Studio and run your application (using the green triangle in the top toolbar). If the arrow is greyed-out then then there was a problem importing or building the project.
Wait while the project builds. It isn't that obvious that the project is being built. The only indication might be that there is a small spinner. If the build process succeeds you will see a prompt to choose a device. Your phone should be listed there. If it isn't, try disconnecting the phone from the USB and reconnecting it.
Select your phone, click OK and away you go. The application should launch on the phone after a few seconds. If it doesn't, be patient sometimes it takes a while. If it still doesn't work, check back in Android Studio for any errors.
Windows Only: Windows requires the additional step of installing the phone's drivers. Details can be found here http://developer.android.com/tools/extras/oem-usb.html
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.