Create custom button in Android using XML


How to create custom button in android using xml style file . which is placed on drawable folder .

Now, just create shape of the ImageButton to have black shader background.
android:background="@drawable/button_shape"
and the button_shape is the xml file in drawable resource:

    <?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#505050"/>
<corners
android:radius="7dp" />

<padding
android:left="1dp"
android:right="1dp"
android:top="1dp"
android:bottom="1dp"/>

<solid android:color="#505050"/>

</shape>

Happy Coding!!!

Differences and Similarities Between Android and iOS.


Diffen.com, summarize between  differences and similarities Google's Android and Apple's iOS.

Differences:



Android


iOS


Company/Developer Google Apple Inc.
OS family Linux OS X, UNIX
Customizability A lot. Can change almost anything. Limited unless jailbroken
Initial release September 23, 2008 July 29, 2007
Programmed in C, C++, java C, C++, Objective-C
Dependent on a PC or a Mac No No
Easy media transfer depends on model with desktop application
Source model Open source Closed, with open source components.
Open source Kernel, UI, and some standard apps The iOS kernel is not open source but is based on the open-source Darwin OS.
Widgets Yes No, except in NotificationCenter
Call features supported Auto-respond Auto-respond, call-back reminder, do not disturb mode
Internet browsing Google Chrome (or Android Browser on older versions; other browsers are available) Mobile Safari (Other browsers are available)
Available on Many phones and tablets, including
Kindle
Fire(modified android), LG, HTC,
Samsung
, Sony, Motorola, Nexus, and others.
iPod Touch, iPhone, iPad, Apple TV (2nd and 3rd generation)
Interface Touch screen, Smartwatch Touch screen
Messaging Google Hangouts iMessage
Voice commands Google Now (on newer versions) Siri
Maps Google Maps Apple Maps
Video chat Google Hangouts Facetime
App store Google Play – 1,000,000+ Apps. Other app stores like
Amazon
and Getjar also distribute Android apps. (unconfirmed ".APK's")
Apple app store – 1,000,000+ Apps
Market share 81% of smartphones, 3.7% of tablets in North America (as of Jan'13) and 44.4% of tablets in Japan (as of Jan'13). In the United States in Q1 2013 - 52.3% phones, 47.7% tablets. 12.9% of smartphones, 87% of tablets in North America (as of Jan'13) and 40.1% of tablets in Japan (as of Jan'13)
Available language(s) 32 Languages 34 Languages
Latest stable release Android 4.4 Kitkat (October, 2013) 7.1 (March 10, 2014)
Device manufacturer Google, LG, Samsung, HTC, Sony, ASUS, Motorola, and many more Apple Inc
Upcoming releases/Release dates Unknown Unknown
Working state Current Current
Website android.com apple.com


Similarities 



Android


iOS


Dependent on a PC or a Mac No No
Upcoming releases/Release dates Unknown Unknown
Working state Current Current

What is Context in Android?


Interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc. More: http://developer.android.com/reference/android/content/Context.html

and simple answer on stackoverflow gives by Sameer Segal.
As the name suggests, its the context of current state of the application/object. It lets newly created objects understand what has been going on. Typically you call it to get information regarding another part of your program (activity, package/application)
You can get the context by invoking getApplicationContext(), getContext(), getBaseContext() or this (when in the activity class).
Typical uses of context:

  • Creating New objects: Creating new views, adapters, listeners:
    TextView tv = new TextView(getContext());
    ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
  • Accessing Standard Common Resources: Services like LAYOUT_INFLATER_SERVICE, SharedPreferences:
    context.getSystemService(LAYOUT_INFLATER_SERVICE)   
    getApplicationContext
    ().getSharedPreferences(*name*, *mode*);
  • Accessing Components Implicitly: Regarding content providers, broadcasts, intent
    getApplicationContext().getContentResolver().query(uri, ...);
Code Here Code explain on video , Watch on youtube:

Vogella gives example, you can check the size of the current device display via the Context.
The Context class also provides access to Android services, e.g., the alarm manager to trigger time based events.
Activities and services extend the Context class. Therefore they can be directly used to access the Context. More: http://www.vogella.com/tutorials/Android/article.html

Happy Coding!!!                                

Android error: Failed to install *.apk on device *: timeout


Do most important this, when your faced this problem, lets hope you have to through away this problem.

Try changing the ADB connection timeout. I think it defaults that to 5000ms and I changed mine to 10000ms to get rid of that problem.
If you are in Eclipse, you can do this by going through

Window-> Preferences -> Android -> DDMS -> ADB Connection Timeout (ms)

Sometime, it works by doing this also:
don't use USB 3.0 ports for connection beetwen PC and Android phone!
USB 3.0 - Port with blue tongue
USB 2.0 - Port with black tongue

Happy coding!!!

Jar Mismatch Found 2 versions of android-support-v4.jar in the dependency list



Step #1: Undo all that. If you are messing with the build path, on R16 or higher version of the ADT plugin for Eclipse, you're doing it wrong.
Step #2: Pick one of those two versions of the JAR, or pick the one from the "extras" area of your SDK installation.
Step #3: Put the right JAR in App Library.
Step #4: Delete the one from App Free, since it will pick up that JAR from App Library.
You are welcome to instead have the same actual JAR file in both spots (App Free and App Library), though that just takes up extra space for no reason.
This wrote CommonsWare.
may work some time for this:
Delete android-support-v4.jar from library and project. Then go in <sdk>/extras/android/support/samples/Support4Demos/ and copy android-support-v4.jarand paste in libs folder of both.

and finally all of not working, then try this:
  1. Delete android-support-v4.jar from App Free
  2. Add the same file from App Library to App Free

How to disable orientation change in Android?

Some of the application that if you want to disable orientation in android, then try some of the tricks, which is not 100% working all level of API.

In Stackoverflow, Intrications   give most reliable and useful answers, 
Add android:configChanges="keyboardHidden|orientation" to your AndroidManifest.xml. This tells the system what configuration changes you are going to handle yourself - in this case by doing nothing.
<activity android:name="MainActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
However, your application can be interrupted at any time, e.g. by a phone call, so you really should add code to save the state of your application when it is paused.
Update: As of Android 3.2, you also need to add "screenSize":
<activity
android:name="MainActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize">
Caution: Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the "screenSize" value in addition to the "orientation" value. That is, you must declare android:configChanges="orientation|screenSize". However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
Or , Yoni Samlan gives highest voted in stackoverflow about orientation change 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">
and followed of other answers where you may be use this,
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
setRequestedOrientation
(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
Sometimes it works also, don't forget to set this, if the above not working,

android:screenOrientation="nosensor" android:configChanges="keyboardHidden|orientation"


How to create Transparent Activity in Android?

You have to add the following style In your res/values/styles.xml file (if you don’t have one, create it.) Here’s a  gnobal code from stackoverflow.


<?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 res/values/color.xmlfile. You can also use @android:color/transparent in later Android versions)
Then apply the style to your activity, for example:
<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
...
</activity>
Another way to make transparentable, like this
<activity android:name=".usual.activity.Declaration" android:theme="@android:style/Theme.Translucent.NoTitleBar" />

 If you want to using ShowCaseView then try this:
Using this:
View showcasedView = findViewById(R.id.view_to_showcase);
ViewTarget target = new ViewTarget(showcasedView);
ShowcaseView.insertShowcaseView(target, this, R.string.showcase_title, R.string.showcase_details);

Here is the best example of dwonload code from : AndroidHub4You 

Problem: Android : CalledFromWrongThreadException;: Only the original thread that created a view hierarchy can touch its views

Avoid performing long-running operations (such as network I/O) directly in the UI thread — the main thread of an application where the UI is run — or your application may be blocked and become unresponsive. Here is a brief summary of the recommended approach for handling expensive operations:
  1. Create a Handler object in your UI thread
  2. Spawn off worker threads to perform any required expensive operations
  3. Post results from a worker thread back to the UI thread's handler either through a Runnable or a Message
  4. Update the views on the UI thread as needed

AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.

So Here is the best solutions:

ou have to move the portion of the background task that updates the ui onto the main thread. There is a simple piece of code for this:
runOnUiThread(new Runnable() {
@Override
public void run() {

//stuff that updates ui

}
});

Documentation for Activity.runOnUiThread.


or you may use this:

Basically you would wrap //do whatever you wantin a Runnable and invoke it with a Handler instance.

Handler refresh = new Handler(Looper.getMainLooper());
refresh
.post(new Runnable() {
public void run()
{
//do whatever you want

}
});

or simple do that:

you don't call directly the onProgressUpdate, you have to call publishProgress and let the AsynTask framework to handle the onProgressUpdate to be called back on the UI thread.


Finally, google it : Here is the best solutions that reach there. Gooogled




Happy Coding!!!