Duplicate Shortcut icon on Android - java

I followed How can I add my application's shortcut to the homescreen upon app installation? to have shortcut icon of my app on screen. It is working fine. But the issue is when I click on the shortcut icon to launch, it creates one more shortcut icon.
How to avoid that? In case I delete one icon, the app creates it again on opening.

I use a flag in Shared Preferences to keep track of whether I created a shortcut already or not. From what I could find, there's no way to check if the shortcut already exists on the home screen.

I tried with sharedpreference and saved its value first time and checking on next call before calling method to create shortcut. Working fine now.

Related

How can Take permission using an alert Box at just destroy the application in Android

I just want to show an alert box at just killing the application in android.
It's like a Notepad application, if we simply kill the app (on clicking the close button) then we get an alert box asking for save changes.
I just want to add same thing in my application.I have tried onBackPressed() and its working fine on clicking on Back Button. But I need same thing on closing the application.
There is now way to be sure if the app is being closed but you can place a check if the application is in foreground or not which is a better metric IMHO as this tells you when the user moved away from your application.
To check the ProcessLifeCycleOwner this will help you find state of process. You can check this Github sample or this stackoverflow question in how to use it.

Android Studio: Text cursor disappears/gone after open some other class or pasting text in different classes

Android Studio: Text cursor disappears/gone after open some other class or pasting text in different classes.
Cursor is randomly disappear while coding in Android Studio. Currently using version 1.5.1
Some time cursor is only visible in one file either in java or xml
Right click is working but cursor is not visible in java/ or xml file so I am not able to type the code.
Observed scenario
The text cursor is not visible or the cursor is gone when I open a different file (e.g. ApplicationTest.java instead of activity_main.xml) the cursor appears again.
Expected scenario:
The text cursor should be located after the insertion point.
Action taken to solved
I used synchronize, restart Android Studio….. but not able to get solution.
I am using window 7 and I have cleared temp
R&D https://code.google.com/p/android/issues/detail?id=78384
I stuck to this problem so please help me. Appreciate, if anyone can help to troubleshoot.
command + O
type some words
esc
cursor appear, works for me
Just update the date time to proper date time.
Permanent workaround: 1
After studying a lot, I found that my system time was incorrect. (On my pc, it was because of windows time service error and not because of CMOS battery. while in some cases CMOS battery may cause this.).
Just update correct the date/time and the cursor will be visible.
If it is still not, close android studio, update correct and start android studio again.
Permanent workaround: 2
Reinstall windows and immediately install antivirus before installing any other software. (Mome malware can affect the working of time service in PC.). (Those who keep antivirus setup file/s on PC itself or USB device, they must check out whether the setup is clear in itself.).
Workaround: 3
On the left pane in android studio, strangely, all my classes were shown as singleton while they weren't.
I pressed multiple combinations multiple times of alter / shift / ctrl / mouse clicks to to check whether any key is stuck (which seldom happens).
I put Android Studio into power save mode: android studio -> file -> power save mode and tried to work again.
I corrected my system date (it was 2 days behind than current.)
Restarted the PC. The issue is resolved.
Disabled power save mode.
Temporary solution:
No need to close project or android studio.
Click on the scroll button on the right of the editing pane or on suggestions yellow lines somewhere else on the same vertical scroll bar line.
I have same problem too
but I solved with this trick..
Go to File-> Invalidate Caches / Restart
Now cursor should appear..
When the cursor disappeared, you can press Insert key on your keyboard, then the cursor will be appeared again.
Go back and check again.. You might find cursor there..
I am using 3.1.2 of AS on Mac. I faced the same problem after pasting multiple classes in AS. While cursor was gone I was able to make text selection. I checked StackOverflow for the solution and reached this question. After reading a couple of answers I went back to AS workspace and cursor was there...
In Android Studio 4.2 this issue still exists. I've deleted the settings file of the android studio folder by folder to find out which file is causing the error. In windows If you navigate to
C:\Users\{User}\AppData\Roaming\Google\AndroidStudio4.2\options
you will see an other.xml file. You can delete this file. This might fix the issue (at least it fixes it in my case). You can also comment out or delete this line in the other.xml file to fix the issue
<property name="Source Code Editor With PreviewLayout" value="Preview only" />
Just follow this answer for faster solution.
Original Post
In my case the cursor was disappearing when I opened a file/class from recent files dialog. When I deleted a file from the list and opened it again (for example: ctrl + n -> go to class) the cursor was there but then opened it again and the cursor was gone.
The solution for me was to restore default settings from Android studio (invalidate caches/restart didn't help me).
Edit October 2021
It happened again (AS 2020.3.1 running on Ubuntu 20.04)
After restoring to default settings AS makes a backup of your settings files to ~/.config/Google/AndroidStudio2020.3-backup.
I just deleted new files in ~/.config/Google/AndroidStudio2020.3 and copy there the old files and it works! (I didn't proceed through the initial setup of AS, but open my project, then exited it, replaced old settings files and then run again.)
Close the android studio, not just the project instead the IDE. then open it again, wait till it build and then cursor appears.
You might have column select on by accident, turn it off with
ALT + SHIFT + I
this happens because some other text editor is open on PC........close that text editor/other instance of android studio and this will be solved....

Open the phone default launcher when clicking a button

I want to open the phone default launcher, where all the phone's applications are displayed, whenever i click my button.
I've tried to look up for an answer but i couldn't find one,
Is that even possible?
Maybe by passing a category to an intent?
To open the Menu, (as per original question):
Use Activity.openOptionsMenu() method in the OnClickListener of the button
Edit:
Edited question as per OP's comments to open launcher, please refer solution at
How to redirect User to default launcher in an android app?

Settings activity

I am making an new android app and I would like to make a settings activity where the use can see about info and settings.
So on android devices you have buttons for settings or else it is presented on screen, when I click that button I do get a menu with the name settings (which I guess eclipse once made automatically) and I do have a activity_settings (as a launcher activity, I don't know if that has any influence or what it means actually) but how can I link the menu tab and the activity?
I mean that when in the menu is clicked on the settings-tab the activity opens.
Can you help me out?
Thanks in advance,
Ide
Yes, what Samarth is saying is true. Read the developer guide before you post questions here. A simple google search will give you links as well.
Here's a complete explanation on how to implement Menus and how to do it: http://developer.android.com/guide/topics/ui/menus.html
Also a similar question on how to create an option Menu: Android, How to create option Menu

Eclipse shortcut for switching current working set

I have several working sets in my eclipse which i often switch from one to another, is there any shortcuts for this so i don't have to click the "view menu" button and click the working set in it every time when i want to switch?
Thanks.
You can set up in preferences/Window working sets.
See this reference for your answer.
Source

Categories