How To Kill Camera Activity Running in Background

All your problems with Audio, Video and Images.

How To Kill Camera Activity Running in Background

Postby vipulshah2010 » Wed Mar 10, 2010 9:00 am

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package org.PUP;
  3.  
  4.  
  5.  
  6. import java.io.FileNotFoundException;
  7.  
  8. import java.io.IOException;
  9.  
  10. import java.io.OutputStream;
  11.  
  12.  
  13.  
  14. import android.app.Activity;
  15.  
  16. import android.content.ContentValues;
  17.  
  18. import android.content.Intent;
  19.  
  20. import android.database.Cursor;
  21.  
  22. import android.graphics.Bitmap;
  23.  
  24. import android.net.Uri;
  25.  
  26. import android.os.Bundle;
  27.  
  28. import android.provider.MediaStore;
  29.  
  30. import android.provider.MediaStore.Images;
  31.  
  32. import android.provider.MediaStore.Images.Media;
  33.  
  34.  
  35.  
  36. public class Cam extends Activity
  37.  
  38. {
  39.  
  40.         static String FilePath;
  41.  
  42.         @Override
  43.  
  44.         public void onCreate(Bundle savedInstanceState)
  45.  
  46.        
  47.  
  48.         {
  49.  
  50.         super.onCreate(savedInstanceState);
  51.  
  52.         Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
  53.  
  54.        
  55.  
  56.         startActivityForResult(intent, 1);
  57.  
  58.         }
  59.  
  60.        
  61.  
  62.        
  63.  
  64.         @Override
  65.  
  66.         protected void onActivityResult(int requestCode, int resultCode, Intent data)
  67.  
  68.         {
  69.  
  70.                 if(requestCode==1)
  71.  
  72.                 {
  73.  
  74.                        
  75.  
  76.                          Bitmap x = (Bitmap) data.getExtras().get("data");
  77.  
  78.              ContentValues values = new ContentValues();
  79.  
  80.              values.put(Images.Media.TITLE, "title");
  81.  
  82.              values.put(Images.Media.BUCKET_ID, "test");
  83.  
  84.              values.put(Images.Media.DESCRIPTION, "test Image taken");
  85.  
  86.              values.put(Images.Media.MIME_TYPE, "image/jpeg");
  87.  
  88.              Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
  89.  
  90.              OutputStream outstream;
  91.  
  92.              try
  93.  
  94.              {
  95.  
  96.                outstream = getContentResolver().openOutputStream(uri);
  97.  
  98.                x.compress(Bitmap.CompressFormat.JPEG, 70, outstream);
  99.  
  100.                outstream.close();
  101.  
  102.              }
  103.  
  104.              catch (FileNotFoundException e)
  105.  
  106.              {
  107.  
  108.              
  109.  
  110.              }
  111.  
  112.              catch (IOException e)
  113.  
  114.              {
  115.  
  116.              
  117.  
  118.              }
  119.  
  120.              String [] proj={MediaStore.Images.Media.DATA};
  121.  
  122.              final Cursor cursor = managedQuery(uri,  
  123.  
  124.                      proj,
  125.  
  126.                      null,      
  127.  
  128.                      null,      
  129.  
  130.                      null);  
  131.  
  132.              int column_index= cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);  
  133.  
  134.              cursor.moveToFirst();  
  135.  
  136.              FilePath=cursor.getString(column_index);    
  137.  
  138.              Main.flag=2;      
  139.  
  140.              Intent in= new Intent(Cam.this,Gal.class);
  141.  
  142.              startActivity(in);
  143.  
  144.                 }
  145.  
  146.         }
  147.  
  148. }
  149.  
  150.  
Parsed in 0.041 seconds, using GeSHi 1.0.8.4




I have written the above code to take a snap using android inbuilt camera.
and its doing fine.
but the serious issue that i m facing is i have coded such that first my another screen
should open and after clicking the button on that screen i must come on this screen(i.e Camera)
but when i launch my app it directly shows this screen without showing my first screen.
but when i restart my mobile and run this code agin it shows that screen first and then this screen.
that is correct.that why sometimes after launching app it directly jumps to camera screen.
my friend suggested me that it is beacause camera activity may be running in background.but he is also not sure
then also i want any of your suggestion for avoiding this abnormal behavior of app.and how to kill that camera activity.
plz hlp
Thnx in Advance :)
vipulshah2010
Junior Developer
Junior Developer
 
Posts: 14
Joined: Tue Feb 09, 2010 7:50 am
Location: India

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 11 guests