Singletons in Android

Portable Droid

There was a surprisingly acrimonious discussion about this, in the Android Developer’s Google Group, recently. Apparently the topic can be confusing.

The issue is that developers occasionally find themselves in need of a singleton. As a pattern, I would say that use of singletons has pretty well been discredited (see, e.g., WhySingletonsAreControversial ). Still, in Android, in a muli-activity application, it is entirely likely that there will be shared data and the desire to store that shared data in some place that is accessible to all application activities.

The problem with Singletons is that they really don’t exist. An instance of some kind of state is only a singleton within some context. A “singleton” on your phone is, clearly, not the same as the instance of the same singleton on my phone. It is even possible that the instance of the singleton on my phone this morning isn’t the same…

View original post 998 more words

Advertisements

Facebook Login and Integration to use Fb Profile Pic and Profile-Name

amandeepsinghme3

References from Facebook , StackOverflow.com , tutorialspoint.com were considered.

Profile Pic and Name token from Fb were made to insert in database.

Getting Started Android SDK

The Facebook SDK for Android is the easiest way to integrate your Android app with Facebook. It enables:

The SDK has UI elements for your app such as pickers and dialogs.

Install and Import

Follow the guide below to configure a Facebook App ID with your Android app’s settings:

Quick Start for Android

If you are using the SDK with Eclipse, see Setup for Eclipse

Related guides:

Android Studio Setup

To…

View original post 2,919 more words

Communicating between Fragments in Android

The Code World

Fragments in Android

A fragment is a portion of a User Interface in android. It’s a component that can be reused as many times as you want.

A particular UI can contain as many Fragments as you want. You can find more about fragments in android by clicking this.

The article is about communicating between various fragments. Let’s quickly shift our focus to that.

Given below is a diagram representing a Tablet and a Handset. (Diagram is self-explanatory.)

Communication between Fragments Communication between Fragments

Here for Tablet, there is an activity A that contains two fragments A and B. Clicking a List Item in fragment A updates the fragment B accordingly. Let’s say, Fragment A has list of image files. Fragment B has an image viewer. Clicking an element in ListView of  Fragment A, updates the image viewer in Fragment B with the selected image.

For the Handset, two fragments are in…

View original post 269 more words

Android Custom Toggle Button Example (iOS like toggle buttons)

Just Another Android Wanderer

Toggle buttons are a great way of getting user input when we need only either yes or no from user. Technically speaking, when we need user input in boolean form- toggle buttons can come handy.

Adding a toggle button to your view and getting its status is very easy, you can have a look what Google has to say about them here.

But, toggle buttons provided with sdk are slightly dull and you just can’t go around and use them everywhere. Well, you can use different images for toggle button states. You can define a button for its checked state and other button for unchecked state. With this you can get a switch-look also.

Lets look how you can get a custom toggle button in your application. The images we are using for different states are inspired from toggle button of iOS, I found them classy (lets have a…

View original post 131 more words

How to create custom Dialog Box in android ?

Android Hub

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.

Dialog is the way where user get notify by app in very clean manner.Dialog is useful for showing alert text, Simple information , show List ,and even you can get value from dialog also.

Android is provide default theme for dialog but if you want to create your own custom dialog then its very easy to build and it will improve your app’s look.

So here i will show you a simple example to create custom dialog and same way  you can create any type of dialog as you want.

We will create separate class name with CustomDialogClass which will extent Dialog class and implement android.view.View.OnClickListener.

If you want…

View original post 282 more words

Android : Tabs + ViewPager (Swipe-able Tabs, FTW)

I Should Write This $#!T Down

In my previous two posts, I explained how you would implement Tabs using Fragments and then how to implement page swiping using ViewPager.  In this post, I’ll bring those two nuggets together and show you how to implement Swipe-able Tabs (i.e switch between tabs using the swipe gesture).

* Caveat Alert * At the time of this posting, there is no way of implementing MapView as a fragment, which may put a spanner in the works if you’re thinking about using this UI pattern with a MapView.

Requirements

To implement a Tabs & ViewPager, using fragments on devices running Android 2.1 or higher, you’ll need to include the Android Compatibility library.  In my example, I’m using Compatibility library v4.

Step-by-step

  1. Define the Tab ViewPager layout
  2. Define the PagerAdapter
  3. Define the Tab FragmentActivity

The Code

The Tab ViewPager layout

The Tab ViewPager layout (tabs_viewpager_layout.xml) declares a TabHost and child TabWidget

View original post 275 more words