Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android resource of type long

There is a type Integer in the Android resources:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <integer name="bytes_size">2147483647</integer>
</resources>

The maximum value is then 2147483647, so how could I have a bigger value in there, like a long? Do I have to put it as a String and then transform it to a long, or is there a better way?

like image 255
galex Avatar asked Mar 24 '15 16:03

galex


People also ask

What is long in Android?

The Long class wraps a value of the primitive type long in an object. An object of type Long contains a single field whose type is long . In addition, this class provides several methods for converting a long to a String and a String to a long , as well as other constants and methods useful when dealing with a long .

What is the use of getResources () in Android?

The documentation for getResources() says that it will [r]eturn a Resources instance for your application's package. In code examples I've seen this used to access the resources in res , but it seems like you can just access them directly. For example to retrieve my_string from res/values/strings.

Why resources in Android should be externalised?

Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more. You should always externalize app resources such as images and strings from your code, so that you can maintain them independently.


1 Answers

Not the ideal solution but you can store the value as a string and parse it during runtime.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="bytes_size">4294967296</string>
</resources>

Now you simply parse it into long.

String longString = getResources().getString(R.string.bytes_size);
long bytes_size = Long.parseLong(longString);
like image 90
Shakti Avatar answered Oct 03 '22 19:10

Shakti