Tuesday, 23 August 2011

Rotate animation in andorid

 RotateAnimation for rotating about a point

<?xml version="1.0" encoding="utf-8"?>
<rotate
    android:fromDegrees="90"
    android:toDegrees="0"
    android:pivotX="-5%"
    android:pivotY="5%p"
    android:duration="3000" />

Alpha Animation in android

It’s up to us to define the alpha animation the way we want it. Alpha animations are generally used to fade drawable objects in and out based on the configuration. For our sample, we want to fade in our text from nothing over the course of three seconds. This configuration appears as below.

Create alpha.xml in anim folder of resources.
AlphaAnimation for fading in and out






<?xml version="1.0" encoding="utf-8"?>
<alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="3000" />


And write following code in the Java file

 Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
    a.reset();
    TextView tv = (TextView) findViewById(R.id.firstTextView);
    tv.clearAnimation();
    tv.startAnimation(a);

Tuesday, 2 August 2011

Opening an Activity with string in Android

  1. try {  
  2.   String className = 'com.almondmendoza.library.openActivity';  
  3.   Intent openNewIntent = new Intent( this, Class.forName( className ) );  
  4.   startActivity(  openNewIntent );  
  5. catch (ClassNotFoundException e) {  
  6.   e.printStackTrace();    

Uploading images from gallery to application

If we want to upload the images ,that are exist in the gallery into our app ,there is a snippet as follows


 Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
 intent.setType("image/*");
 startActivityForResult(intent, IMAGE_PICK);

Click here for source

Monday, 1 August 2011

Exit the application

Store Every Activity obj in a Arraylist. Whenever if you want to exit the app call finishing each of activity. And then call the fallowing.

try{
android.os.Process.killProcess(android.os.Process.myPid());
}cathch(Exception e){
}

Note: Execute the above after finishing all the acivities, Otherwise the app may be getting restarted without intervention of user.

















Tuesday, 3 May 2011

Resolving ANR dilog in case of "Wait"

WARN/WindowManager(88): Key dispatching timed out sending to package name/Activity
WARN/WindowManager(88): Dispatch state: {{KeyEvent{action=1 code=5 repeat=0 meta=0 scancode=231 mFlags=8} to Window{432bafa0 com.android.launcher/com.android.launcher.Launcher paused=false} @ 1281611789339 lw=Window{432bafa0 com.android.launcher/com.android.launcher.Launcher paused=false} lb=android.os.BinderProxy@431ee8e8 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4335fc58 package name/Activity paused=false}}}
WARN/WindowManager(88): Current state:  {{null to Window{4335fc58 package name/Activity paused=false} @ 1281611821193 lw=Window{4335fc58 package name/Activity paused=false} lb=android.os.BinderProxy@434c9bd0 fin=false gfw=true ed=true tts=0 wf=false fp=false mcf=Window{4335fc58 package name/Activity paused=false}}}
INFO/ActivityManager(88): ANR in process: package name (last in package name)
INFO/ActivityManager(88): Annotation: keyDispatchingTimedOut
INFO/ActivityManager(88): CPU usage:
INFO/ActivityManager(88): Load: 5.18 / 5.1 / 4.75
INFO/ActivityManager(88): CPU usage from 7373ms to 1195ms ago:
INFO/ActivityManager(88):   package name: 6% = 1% user + 5% kernel / faults: 7 minor
INFO/ActivityManager(88):   system_server: 5% = 4% user + 1% kernel / faults: 27 minor
INFO/ActivityManager(88):   tiwlan_wifi_wq: 3% = 0% user + 3% kernel
INFO/ActivityManager(88):   mediaserver: 0% = 0% user + 0% kernel
INFO/ActivityManager(88):   logcat: 0% = 0% user + 0% kernel
INFO/ActivityManager(88): TOTAL: 12% = 5% user + 6% kernel + 0% softirq
INFO/ActivityManager(88): Removing old ANR trace file from /data/anr/traces.txt
INFO/Process(88): Sending signal. PID: 1812 SIG: 3
INFO/dalvikvm(1812): threadid=7: reacting to signal 3
INFO/dalvikvm(1812): Wrote stack trace to '/data/anr/traces.txt'
 
 
The solution for the above exception is
 
You must be as fast as possible in your onClick implementation(In <5 sec ), meaning that you have to launch a new Thread as soon as you are doing some important work. In onClick, try:
Threat t = new Thread(){ public void run(){ your_stuff(); } }; t.start();