Android Activity über Service starten?

E

Extremefall

Ambitioniertes Mitglied
3
Hallo,
ich habe eine Activity, die momentan Fotos macht. Diese soll im Hintergrund laufen. Nun würde ich gerne die App mittels Service starten. Leider kann ich bei Eclipse die Service Klasse nicht auswählen. Mein Code ist folgender:
Code:
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<?[/COLOR][/SIZE]
[LEFT][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]xml[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]version[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1.0"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]encoding[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"utf-8"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]?>[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]

[SIZE=2][COLOR=#008080][LEFT][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]manifest[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]xmlns:android[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff][URL]http://schemas.android.com/apk/res/android[/URL][/COLOR][/SIZE][/COLOR][/SIZE][/I]

[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]package[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"location.android.com"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[LEFT][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:versionCode[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:versionName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"1.0"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]


[U][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]uses-sdk[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:minSdkVersion[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"4"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/COLOR][/SIZE][/COLOR][/SIZE][/U]

[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]application[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@string/app_name"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]


[SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]<activity[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".LocationActivity"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@string/app_name"[/COLOR][/SIZE][/COLOR][/SIZE][/I]
[SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:theme[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@style/Theme.Transparent"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]action[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.intent.action.MAIN"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]category[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.intent.category.LAUNCHER"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]


[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE]
[LEFT][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]service[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:enabled[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"true"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".AppService"[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/COLOR][/SIZE][/COLOR][/SIZE]
[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]application[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][/LEFT]

[SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]manifest[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][/LEFT]
[/COLOR][/SIZE]
Meine Service Klasse:​

Code:
package location.android.com;
Code:
[LEFT]import java.io.File;
[LEFT]import java.io.FileOutputStream;
import java.io.OutputStream;
import android.app.Service;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.provider.MediaStore;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.WindowManager;
import android.widget.Toast;
public class AppService extends Service { [/LEFT]
 
[LEFT]@Override public IBinder onBind(Intent intent) {  
 return null; 
 } [/LEFT]
 
 
[LEFT]@Override 
public void onCreate() {
 Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show(); 
 } 
@Override public void onDestroy() {  
 Toast.makeText(this, "My Service Stopped", Toast.LENGTH_LONG).show(); 
 }  
@Override 
public void onStart(Intent intent, int startid) {  
 Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show(); 
 Intent i = new Intent(getBaseContext(), LocationActivity.class); 
 i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); [/LEFT]
 
[LEFT] i.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE); 
 i.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); 
 i.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE); 
 i.setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH); 
 getApplication().startActivity(i); 
 }[/LEFT]
 
 
[LEFT]}[/LEFT]
[/LEFT]

Die Activity Klasse funktioniert sonst, wenn ich sie einfach so ausführe. Wie kann man in Eclipse aber die Service Klasse ausführen? Geht das überhaupt und wenn ja, wie? Oder habe ich da noch etwas vergessen, was man vorher angeben muss?

 
Hi!

Ich find deine Problembeschreibung ist ein wenig ungenau.

Du möchtest eine Activity von einem Service aus starten. Soweit ist klar.
Was hat das mit Eclipse zu tun? Man kann keine Services(und/oder Activities) im Eclipse ausführen.
 
Ich habe nach einer Möglichkeit gesucht, zwischen zwei Activities zu wechseln. Ich dachte, dass es acuh über die GUI möglich ist. Man musste aber die AndroidManifest.xml Datei ändern. Nun rufe ich über die Activity den Service auf, also starte ich diesen darüber. Ich dachte, dass es auch über das UI möglich ist. Aus dem Service heraus starte ich dann die Activity.
 
hmm warum nicht einfach ein intent senden ?

activities wechselt man über startactivity

=> kein service dafür - ein service ist für etwas ganz anderes gut
 
Ich habe nun ein ganz komisches Problem:
Wenn ich eine App mit der Activity OldActivity starte, klappt alles.
Nun habe ich die Activity im Manifest in TakePhoto umbenannt und öffne mittels Intent nun diese Activity. Leider stürzt das Programm dann ab. Woran kann so etwas liegen?
Code:
[SIZE=2]
[LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]application[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@string/app_name"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".TakePhoto"[/LEFT]
[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:label[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@string/app_name"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 
[/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:theme[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"@style/Theme.Transparent"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]action[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.intent.action.MAIN"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] 
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]category[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"android.intent.category.LAUNCHER"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080][LEFT]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]intent-filter[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]activity[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".StartService"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
[/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]<[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]service[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:enabled[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"true"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#7f007f][SIZE=2][COLOR=#7f007f]android:name[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][I][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".AppService"[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]/>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]</[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f7f][SIZE=2][COLOR=#3f7f7f]application[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008080][SIZE=2][COLOR=#008080]>[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE]
Der Code zum starten der Activity:
Code:
[SIZE=2][LEFT]Intent myIntent = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent(AppService.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], TakePhoto.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/LEFT]
startActivity(myIntent); 
[/SIZE]
Macht das Sinn, dass es mit der einen Klasse funktioniert und der anderen nicht? Sie befinden sich bei im Package app.service.com
 
=> logcat

"leider stürtzt das programm dann ab" ist keine fehlermeldung für den dev bereich :D
 
Ich habe es jetzt scheinbar fast gelöst. Mein Code zum Aufruf der Klasse:

startActivity(
new Intent(StartService.this,TakePhoto.class));


Nun habe ich dort eine Klasse, die ein Foto erzeugen soll. Wenn ich die Klasse so aufrufen (nicht über eine andere Activity Klasse), geht alles. Nur beim Aufruf über die Aktivity Klasse wird das Foto erst nach ungefähr 50 Sekunden geschossen. Woran kann das liegen? Ich erhalte da keine Fehlermeldungen. Außerdem ist es extra über einen Handler auf 10 ms nach festgelegt. Der Auslöser findet sich hier also:

Code:
@Override
publicvoid surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) 
{
mHandlerFoto.removeCallbacks(mUpdateTimeTaskFoto); 
mHandlerFoto.postDelayed(mUpdateTimeTaskFoto, 100);
} 
private Runnable mUpdateTimeTaskFoto = new Runnable() {
publicvoid run() 
parameters = mCamera.getParameters();
parameters.set("camera_id", 2);
mCamera.setParameters(parameters); 
mCamera.startPreview();
Camera.PictureCallback mCall = new Camera.PictureCallback(){
@Override
publicvoid onPictureTaken(byte[] data, Camera camera) 
{
bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
String path = Environment.getExternalStorageDirectory().toString(); 
OutputStream fOut = null; 
File file = new File(path, "Image.jpg"); 
try {
fOut = new FileOutputStream(file);
 
bmp.compress(Bitmap.CompressFormat.JPEG, 85, fOut);
fOut.flush(); 
fOut.close();
 
MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
}
catch (Exception e) {
// TODO Auto-generated catch block
}
}
}; 
mCamera.takePicture(null, null, mCall); 
//moveTaskToBack (true); 
}
};
Wodurch kann diese Zeitverzögerung entstehen?​
 
Zuletzt bearbeitet:

Ähnliche Themen

Laser5001
  • Laser5001
Antworten
2
Aufrufe
900
Laser5001
Laser5001
M
Antworten
4
Aufrufe
1.171
swa00
swa00
5
Antworten
0
Aufrufe
1.146
586920
5
Zurück
Oben Unten