onActivityResult is not being called in Fragment

The hosting activity overrides onActivityResult(), but it did not make a call to super.onActivityResult() for unhandled result codes. Apparently, even though the fragment is the one making the startActivityForResult() call, the activity gets the first shot at handling the result. This makes sense when you consider the modularity of fragments. Once I implemented super.onActivityResult() for … Read more

How do I create a transparent Activity on Android?

Add the following style in your res/values/styles.xml file (if you don’t have one, create it.) Here’s a complete file: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <style name=”Theme.Transparent” parent=”android:Theme”> <item name=”android:windowIsTranslucent”>true</item> <item name=”android:windowBackground”>@android:color/transparent</item> <item name=”android:windowContentOverlay”>@null</item> <item name=”android:windowNoTitle”>true</item> <item name=”android:windowIsFloating”>true</item> <item name=”android:backgroundDimEnabled”>false</item> </style> </resources> (The value @color/transparent is the color value #00000000 which I put in the res/values/color.xml file. … Read more

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

This is the activity the tools UI editor uses to render your layout preview. It is documented here: This attribute declares which activity this layout is associated with by default. This enables features in the editor or layout preview that require knowledge of the activity, such as what the layout theme should be in the … Read more

How to create RecyclerView with multiple view types

Yes, it’s possible. Just implement getItemViewType(), and take care of the viewType parameter in onCreateViewHolder(). So you do something like: public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { class ViewHolder0 extends RecyclerView.ViewHolder { … public ViewHolder0(View itemView){ … } } class ViewHolder2 extends RecyclerView.ViewHolder { … public ViewHolder2(View itemView){ … } @Override public int getItemViewType(int position) { … Read more

Can’t start Eclipse – Java was started but returned exit code=13

Your version of Eclipse is 64-bit, based on the paths and filenames. However, the version of Java that it’s picking up is 32-bit, as indicated by where it is coming from, on this line: -vm C:\Program Files (x86)\Java\jre7\bin\javaw.exe Program Files (x86) is the folder where 64-bit Windows places 32-bit programs. Program Files is the folder … Read more

How can I disable landscape mode in Android?

Add android:screenOrientation=”portrait” to the activity in the AndroidManifest.xml. For example: <activity android:name=”.SomeActivity” android:label=”@string/app_name” android:screenOrientation=”portrait” /> Since this has become a super-popular answer, I feel very guilty as forcing portrait is rarely the right solution to the problems it’s frequently applied to. The major caveats with forced portrait: This does not absolve you of having to … Read more

How to check if a service is running on Android?

I use the following from inside an activity: private boolean isMyServiceRunning(Class<?> serviceClass) { ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if (serviceClass.getName().equals(service.service.getClassName())) { return true; } } return false; } And I call it using: isMyServiceRunning(MyService.class) This works reliably, because it is based on the information about running services provided by … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)