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!!!

How to lazy load of images in ListView or LazyList?

Lazy List is lazy loading of images from sd-card or from server using urls. It is like on demand loading images.
Images can be cached to local sd-card or phone memory. Url is considered the key. If the key is present in sd-card, display images from sd-card else display image by downloading from server and cache the same to location of your choice. The cache limit can set. You can also choose your own location to cache images. Cache can also be cleared.
Instead of user waiting to download large images and then displaying lazy list, loads images on demand. Since images are cached you can display images offline.
A simple library to display images in Android ListView. Images are being downloaded asynchronously in the background. Images are being cached on SD card and in memory. Can also be used for GridView and just to display images into an ImageView.
other examples:
James A Wilson give the best examles of highest vote on stackover.
package com.wilson.android.library;


import java.io.IOException;

public class DrawableManager {
private final Map<String, Drawable> drawableMap;

public DrawableManager() {
drawableMap
= new HashMap<String, Drawable>();
}

public Drawable fetchDrawable(String urlString) {
if (drawableMap.containsKey(urlString)) {
return drawableMap.get(urlString);
}

Log.d(this.getClass().getSimpleName(), "image url:" + urlString);
try {
InputStream is = fetch(urlString);
Drawable drawable = Drawable.createFromStream(is, "src");


if (drawable != null) {
drawableMap
.put(urlString, drawable);
Log.d(this.getClass().getSimpleName(), "got a thumbnail drawable: " + drawable.getBounds() + ", "
+ drawable.getIntrinsicHeight() + "," + drawable.getIntrinsicWidth() + ", "
+ drawable.getMinimumHeight() + "," + drawable.getMinimumWidth());
} else {
Log.w(this.getClass().getSimpleName(), "could not get thumbnail");
}

return drawable;
} catch (MalformedURLException e) {
Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
return null;
} catch (IOException e) {
Log.e(this.getClass().getSimpleName(), "fetchDrawable failed", e);
return null;
}
}

public void fetchDrawableOnThread(final String urlString, final ImageView imageView) {
if (drawableMap.containsKey(urlString)) {
imageView
.setImageDrawable(drawableMap.get(urlString));
}

final Handler handler = new Handler() {
@Override
public void handleMessage(Message message) {
imageView
.setImageDrawable((Drawable) message.obj);
}
};

Thread thread = new Thread() {
@Override
public void run() {
//TODO : set imageView to a "pending" image
Drawable drawable = fetchDrawable(urlString);
Message message = handler.obtainMessage(1, drawable);
handler
.sendMessage(message);
}
};
thread
.start();
}

private InputStream fetch(String urlString) throws MalformedURLException, IOException {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet(urlString);
HttpResponse response = httpClient.execute(request);
return response.getEntity().getContent();
}
}
Alternative of LazyList is:

open source instrument Universal Image Loader. It is originally based on Fedor Vlasov's project LazyList and has been vastly improved since then.
  • Multithread image loading
  • Possibility of wide tuning ImageLoader's configuration (thread executors, downlaoder, decoder, memory and disc cache, display image options, and others)
  • Possibility of image caching in memory and/or on device's file sysytem (or SD card)
  • Possibility to "listen" loading process
  • Possibility to customize every display image call with separated options
  • Widget support
  • Android 2.0+ support
Finally, you may use this also,this is also best tutoiral for lazylist image loader.
I have followed this Android Training and I think it does an excellent job at downloading images without blocking the main UI. It also handles caching and dealing with scrolling through many images: Loading Large Bitmaps Efficiently

All sources from statckover.

Happy Coding!!!