Android Developer

854

votes
6

answer
204.1k

views

What's “tools:context” in Android layout files?

Starting with a recent new version of ADT, I've noticed this new attribute on the layout XML files, for example: What is 'tools:context' used for? How does it even know the exact path to the activity that is written there? Does it look at the package of the app, inside the manifest? Is it limited to...
391

votes
12

answer
137.1k

views

Android - I need some clarifications of fragments vs activities and views

In Android API 11+, Google has released a new class called Fragment. In the videos, Google suggests that whenever possible (link1, link2), we should use fragments instead of activities, but they didn't explain exactly why. What's the purpose of fragments and some possible uses of them (other than so...
391

votes
12

answer
137.4k

views

Why fragments, and when to use fragments instead of activities?

In Android API 11+, Google has released a new class called Fragment. In the videos, Google suggests that whenever possible (link1, link2), we should use fragments instead of activities, but they didn't explain exactly why. What's the purpose of fragments and some possible uses of them (other than so...
300

votes
16

answer
193.5k

views

Running the new Intel emulator for Android

Lately Google and Intel have published a new way to run the emulator, which should work much better than the previous version (which has emulated ARM CPU). Here are some links about it: this and this. However, after installing the new components and creating a new emulator configuration as instructe...
222

votes
15

answer
168.3k

views

Auto-fit TextView for Android

Background Many times we need to auto-fit the font of the TextView to the boundaries given to it. The problem Sadly, even though there are many threads and posts (and suggested solutions) talking about this problem (example here, here and here), none of them actually work well. That's why, I've deci...
android developer
215

votes
5

answer
110.2k

views

What is “android:allowBackup”?

Since the new ADT preview version (version 21), they have a new lint warning that tells me the next thing on the manifest file (in the application tag): Should explicitly set android:allowBackup to true or false (it's true by default, and that can have some security implications for the application'...
android developer
104

votes
3

answer
67.9k

views

How to use the new SD card access API presented for Android 5.0 (Lollipop)?

Background On Android 4.4 (KitKat), Google has made access to the SD card quite restricted. As of Android Lollipop (5.0), developers can use a new API that asks the user to confirm to allow access to specific folders, as written on the this Google-Groups post . The problem The post directs you to vi...
android developer
96

votes
3

answer
44.4k

views

Need some clarification about beta/alpha testing on the developer console

Background The Android developer console has 3 tabs for publishing the app's apk file: alpha, beta and production, as shown here: as I recall from one of Google IO lectures, one cool way to check how good is your app before making a 100% scale publishing, is to allow only a percentage of the users t...
android developer
96

votes
3

answer
23.8k

views

How to mimic Google Maps' bottom-sheet 3 phases behavior?

Background I'm assigned to make a UI that behaves similar to how Google Maps shows a bottom-sheet for a found result. It has three different phases: Bottom content. The upper area is still touchable and won't scroll anything at the bottom Full screen content, while the upper area has a large header....
android developer
86

votes
9

answer
48.9k

views

VectorDrawable - is it available somehow for pre-Lollipop versions of Android?

Background I've noticed that Android now supports some kind of vector drawing, via a class called 'VectorDrawable' (and also AnimatedVectorDrawable, BTW). I've found about it by looking at what's new on Android-Studio. I wonder if this would be the end of having to put multiple files into multiple f...
android developer
81

votes
5

answer
41.7k

views

How to make a circular ripple on a button when it's being clicked?

Background On the dialer app of Android, when you start searching for something, and you click the arrow button on the left of the EditText, you get a circular ripple effect on it : The problem I've tried to have it too, but I got a rectangular one: The question How do I make the button have a circu...
android developer
79

votes
2

answer
24.8k

views

What's “requestCode” used for on PendingIntent?

Background: I'm using PendingIntent for alarms via AlarmManager. The problem: At first I thought that in order to cancel previous ones, I must provide the exact requestCode that I've used before to start the alarm. But then I've found out I was wrong, as the cancellation API says: Remove any alarms...
android developer
77

votes
8

answer
137.1k

views

How to use the TextWatcher class in Android?

Can anyone tell me how to mask the substring in EditText or how to change EditText substring input to password type or replace by another character like this 123xxxxxxxxx3455 String contents = et1.getText().toString(); et1.setText(contents.replace.substring(0, contents.length()-2),'*'); Please, tell...
Android developer
72

votes
12

answer
76.5k

views

How to use the legacy Apache HTTP client on Android Marshmallow?

Background On Android Marshmallow, Google has completely removed the support of Apache HTTP client (link here) because it doesn't have good performance compared to the alternatives. This might also be the cause for so many apps crashing on Android Marshmallow. The problem Google allows you to still...
69

votes
1

answer
11k

views

Firebase JobDispatcher - how does it work compared to previous APIs (JobScheduler and GcmTaskService)?

Background Google has multiple solutions for job/task scheduling, such as JobScheduler and GcmTaskService. Each has its own advantages and disadvantages. Recently, Google presented a new library called 'Firebase JobDispatcher'. The problem Sadly, there is very little to read about this new API. In f...
68

votes
9

answer
40.7k

views

How to add a fast-scroller to the RecyclerView

Background On ListView, you could have a fast scroller which allowed you to drag a scrollbar to easily scroll to wherever you wished (using fastScrollEnabled attribute) Together with 'SectionIndexer' class and optionally some attributes, you could have a nice popup that shows as you use this scrollb...
android developer
62

votes
3

answer
1.7k

views

How to fit video in Live wallpaper, by center-crop and by fitting to width/height?

Background I'm making a live wallpaper that can show a video. In the beginning I thought this is going to be very hard, so some people suggested using OpenGL solutions or other, very complex solutions (such as this one). Anyway, for this, I've found various places talking about it, and based on this...
android developer
61

votes
2

answer
15.2k

views

How to disable scrolling of NestedScrollView&CollapsingToolbarLayout, for example when there is no more content below?

Background I try to add the same functionality as shown on many apps, where the upper area of the screen shrinks&expands according to the scrolled content. For this, I use Google's design library, as shown on the CheeseSquare sample. The problem Thing is, no matter how much content there is in the N...
android developer
61

votes
6

answer
17.9k

views

Interstitial Admob ads: “IllegalStateException: Only fullscreen activities can request orientation”

Background I have an app with Admob SDK used in it, to show Interstitial ads (full screen ads). Reccently Google has updated the SDK, along with many other things (build tools, gradle plugin, IDE, etc...), including admob (firebase ads). compile 'com.google.firebase:firebase-ads:11.4.2' The problem...
android developer
57

votes
6

answer
7.1k

views

ADT 22.3 (android 4.4) - getting error “After scene creation, #init() must be called”

After installing the new ADT (22.3.0.v201310242005-887826) which supports Android 4.4 (KitKat), I keep getting the error as shown here: An internal error has occurred In the list of errors, I see multiple items of 'RenderPreview', and when I click on any of them, I see: An internal error has occurre...
android developer
55

votes
3

answer
29.6k

views

“minifyEnabled” vs “shrinkResources” - what's the difference? and how to get the saved space?

Background According to the 'Resource Shrinking' webpage of Andriod documentations (here), you can minimize the app's size via the build.gradle file, by using these lines: android { ... buildTypes { release { minifyEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-andr...
54

votes
7

answer
64.4k

views

Is it possible to detect Android app uninstall?

My app is using Google's C2DM (push notification) to notify users about new activity from friends. Once they install the app i register the device with C2DM servers and store user's phone number. So i know that the user is using my app and i can send him/her the push notifications. But what happens...
52

votes
7

answer
27.9k

views

How to sign APK on Android Studio even with non-translated strings?

Background I've recently migrated my app to Android-Studio. I had some issues doing so, but I got over them eventually. The problem For some reason, on Android Studio, when I try to sign an APK, I get a lot of errors that look like this: Error:(16) Error: '...' is not translated in 'de' (German), 'e...
android developer
51

votes
4

answer
99k

views

Get GPS location via a service in Android

I need to monitor user's locations using a background service, and then load them and show the path to the user. Using an activity, it was quite easy to get GPS locations, but when I got to do it via a service, I came into a problem as it seems to only work for looper threads (or something like that...
android developer
51

votes
9

answer
114k

views

How to implement zoom effect for image view in android?

I have to implement image zooming, I have tried with so many codes.But i didnt get full idea of gesture events. I want to implement when we apply double tap, image will be zooming according to the touch place(event x and y).I have to implement only zooming at this time no pan.Can any body suggest me...
50

votes
2

answer
12.6k

views

How to move from Google-Analytics to Firebase-Analytics?

Background In the recent months, Google has published a new Analytics alternative, called 'Firebase Analytics' . The problem As the app already does have Google-Analytics, I find some obstacles that I can't see how to best handle. The questions Previously, 'newTracker' function needed a property-id....
48

votes
7

answer
42.5k

views

How to use UsageStatsManager?

Background Google has deprecated the function 'getRecentTasks' of 'ActivityManager' class. Now all it does is to get the list of apps that the current app has opened. I've even written a post about it here on StackOverflow, but I noticed it's impossible. The problem I've made a post about it (here,...
android developer
47

votes
2

answer
26.9k

views

How does storage access change on Android 6?

Background Android had a lot of changes as to how to handle the SD-card and storage in general: API 3 - you get all access, no permission needed API 4-15 - you need to use WRITE_EXTERNAL_STORAGE, and you get all access. API 16-18 - if you wish only to read, use READ_EXTERNAL_STORAGE API 19-20 - you...
android developer
44

votes
1

answer
29.4k

views

JNI bitmap operations , for helping to avoid OOM when using large images [closed]

background most of the times, getting OOM on android is due to using too many bitmaps and/or creating large bitmaps. recently i've decided to try out JNI in order to allow avoiding OOM by storing the data itself on the JNI side. after messing around with JNI for a while, i've created some posts on...
android developer
42

votes
4

answer
36.9k

views

How to set multiple spans on a TextView's text on the same partial text?

Suppose I have the next text : Hello stackOverflow And I wish to set the second word to be both RelativeSizeSpan (to set a relative font size) and TextAppearanceSpan (to set the color of the text) , how do I merge them both ? All I know is that I can choose one of them , using the next code for exam...
android developer
42

votes
5

answer
12k

views

Is it safe to save the app context to a static variable in Android?

I know that usage of static variables on Android is quite risky, especially if you reference them to activities. However, if I have a class that extends Application (let's call this class 'App'), is it safe to reference to the instance of this class? If so, is it also safe for any other class to hav...
android developer
42

votes
7

answer
41.7k

views

How to mimic the Material-design raised button style, even for pre-Lollipop (minus the special effects)?

Google has shown some nice ways that buttons are shown on Lollipop here. I'm talking about both the raised and the flat buttons. How can I mimic them on pre-Lollipop versions, except for the special effects (ripple etc...) ? I'm talking about this and this. Of course, on Lollipop and above, I'd like...
android developer
42

votes
4

answer
23.6k

views

Using the new “manifestmerger” property in Android

In the newest version of ADT (version 20 preview 3), they say that it's possible to make the libraries' manifest file become mergeable with projects that use them: Automatic merging of library project manifest files into the including project's manifest. Enable with the manifestmerger.enabled proper...
41

votes
3

answer
1.9k

views

How to share split APKs created while using instant-run, within Android itself?

Background I have an app (here) that, among other features, allows to share APK files. In order to do so, it reaches the file by accessing the path of packageInfo.applicationInfo.sourceDir (docs link here), and just shares the file (using ContentProvider when needed, as I've used here). The problem...
android developer
40

votes
3

answer
9k

views

Are there alternatives to using Google's in-app-billing , as a way to avoid publishing private info? [closed]

Background Starting from September 30th this year (end of this month), Google won't allow developers that sell apps and developers that use in-app-billing to show their apps without also showing their address . Here's what they write: Add a physical contact address Beginning September 30, 2014, you...
android developer
38

votes
7

answer
72.8k

views

How to get file name from file path in android

I want to get file name from sdcard file path. e.g. :/storage/sdcard0/DCIM/Camera/1414240995236.jpg I want get 1414240995236.jpg I have written the code to fetch the same but it is not working. Please help. Below is my code: @Override protected void onActivityResult( int requestCode, int resultCode...
38

votes
3

answer
12.7k

views

How to fully replace listView/GridView with RecyclerView?

I've noticed that the new RecyclerView class, even though it makes things a bit cleaner, is lacking a lot of functionality that I'm familiar with: dividers, but this can be solved by looking at this post or this one 'footerDividersEnabled' 'headerDividersEnabled' 'listSelector' , but maybe I should...
android developer
38

votes
2

answer
24.5k

views

Create a transparent dialog on top of activity

Background I'm trying to put a layer on top of the current activity which would have explanation of what is going on on the current screen, similar to what occurs on contact+ app . I know there are some solutions for this (like the showCase library and the superToolTips library ) , and I also know...
android developer
36

votes
2

answer
21.4k

views

How to cache bitmaps into native memory

For my 10,000 points, i've decided to contibute something with this cool website: a mechanism to cache bitmaps on native memory. Background Android devices have a very limited amount of memory for each app- the heap ranges from 16MB to 128MB , depending on various parameters . If you pass this limit...
36

votes
1

answer
2k

views

NPE on Facebook SDK 4.10 : Attempt to invoke interface method 'java.lang.Object com.facebook.inject.Lazy.get()' on a null object reference

Background Recently we've updated the Facebook SDK library to 4.10 (from here). Before, we had the same bug now and then, but now it seems it occurs a lot more often. The problem There is no way for us to understand where and why it occurs. Here's the crash log: Fatal Exception: java.lang.NullPoint...
android developer