How do I detect the heap size usage of an android application

here’s what I use: public static void logHeap() { Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576)); Double available = new Double(Debug.getNativeHeapSize())/1048576.0; Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0; DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(2); df.setMinimumFractionDigits(2); Log.d(“tag”, “debug. =================================”); Log.d(“tag”, “debug.heap native: allocated ” + df.format(allocated) + “MB of ” + df.format(available) + “MB (” + df.format(free) + “MB … Read more

How to access resource with dynamic name in my case?

int id = getResources().getIdentifier(imageName, type, package); This will get you the ID of the resource you are looking for. With it, you can then access the resource from the R class. Using only the name parameter: You can also include all the 3 info in the “name” parameter using the following format: “package:type/image_name”, something like: … Read more

Setting Action Bar title and subtitle

You can do something like this to code for both versions: /** * Sets the Action Bar for new Android versions. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB) private void actionBarSetup() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { ActionBar ab = getActionBar(); ab.setTitle(“My Title”); ab.setSubtitle(“sub-title”); } } Then call actionBarSetup() in onCreate(). The if runs the code only on new Android … Read more

How to create a date and time picker in Android? [closed]

Put both DatePicker and TimePicker in a layout XML. date_time_picker.xml: <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”match_parent” android:padding=”8dp” android:layout_height=”match_parent”> <DatePicker android:id=”@+id/date_picker” android:layout_width=”match_parent” android:calendarViewShown=”true” android:spinnersShown=”false” android:layout_weight=”4″ android:layout_height=”0dp” /> <TimePicker android:id=”@+id/time_picker” android:layout_weight=”4″ android:layout_width=”match_parent” android:layout_height=”0dp” /> <Button android:id=”@+id/date_time_set” android:layout_weight=”1″ android:layout_width=”match_parent” android:text=”Set” android:layout_height=”0dp” /> </LinearLayout> The code: final View dialogView = View.inflate(activity, R.layout.date_time_picker, null); final AlertDialog alertDialog = new … Read more

Android: AppWidget with custom view not working

I pretty much left my custom view intact, and implemented an ImageView for my widget, then rendered the view using the getDrawingCache() MyView myView = new MyView(context); myView.measure(150,150); myView.layout(0,0,150,150); myView.setDrawingCacheEnabled(true); Bitmap bitmap=myView.getDrawingCache(); remoteViews.setImageViewBitmap(R.id.dial, bitmap);

Custom format edit text input android to accept credit card number

Now this works fine for soft/hard keyboard for all delete/edit ops. tx 4 ur help.. package com.and; import android.app.Activity; import android.app.AlertDialog; import android.inputmethodservice.KeyboardView; import android.os.Bundle; import android.telephony.PhoneNumberFormattingTextWatcher; import android.text.Editable; import android.text.Selection; import android.text.Spannable; import android.text.TextWatcher; import android.text.format.Formatter; import android.text.method.NumberKeyListener; import android.view.KeyEvent; import android.view.View; import android.view.View.OnKeyListener; import android.widget.EditText; import android.widget.Toast; public class ccformat extends Activity { … Read more

Is there any example about Spanned and Spannable text

Since you don’t specify what you can’t grasp from the API it’s hard to answer your questions (short answer: rewrite your question to a specific questions rather than a general one). A typical Spannable-example is something like this to turn selected text in an EditText into Italic: Spannable str = mBodyText.getText(); if(mBodyText.getSelectionEnd() > mBodyText.getSelectionStart()) str.setSpan(new … Read more