나는 wipeScreen.java라는 액티비티를 가지고있다.활동을 방해하지 않는 실행중인 서비스를 만드는 방법은 무엇입니까?
이 활동은 android 핸드폰에서 SMS와 연락처를 지우기 위해 wipeService.java를 실행한다. wipeService가 실행 중일 때 내 wipeScreen 활동이 멈추었고 사용할 수 없으며 검은 색 화면 만 표시하고 길게 기다리는 시간에는 "강제 닫기"를 제공합니다.
누구나 서비스를 만드는 방법을 알고 있습니다. 그것은 자기 일을 할 수 있고 활동을 방해하지 않으므로 서비스가 실행 중일 때 활동을 계속 사용할 수 있습니까?
SPWipe = getSharedPreferences("wipe", 0);
editorSPWipe = SPWipe.edit();
editorSPWipe.putString("wipe", "yes");
editorSPWipe.commit();
intent myIntent = new Intent(ListenSMSservice.this,WipeScreenForm.class);
myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(myIntent);
여기 내 wipeScreen 코드입니다 :
여기 내 wipescreen 트리거 코드의
SPtempWipe = getSharedPreferences("wipe", 0);
if (SPtempWipe.getString("wipe","").equalsIgnoreCase("yes"))
{
startService(new Intent(LockScreenForm.this, WipeService.class));
SPWipe = getSharedPreferences("wipe", 0);
editorSPWipe = SPWipe.edit();
editorSPWipe.putString("wipe", "no");
editorSPWipe.commit();
}
여기 내 wipeService 코드입니다 : 서비스가 내 연락처를 제거하기 시작
@Override
public void onStart(Intent intent, int startid) {
Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
wipeSMS();
wipeContact();
stopService(new Intent(this, WipeService.class));
}
public void wipeSMS()
{
Uri uri = Uri.parse("content://sms");
ContentResolver contentResolver = getContentResolver();
Cursor cursor = contentResolver.query(uri, null, null, null,
null);
while (cursor.moveToNext()) {
try {
long thread_id = cursor.getLong(1);
Uri thread = Uri.parse("content://sms/conversations/"
+ thread_id);
getContentResolver().delete(thread, null, null);
} catch (Exception e) {
// TODO: handle exception
}
}
}
public void wipeContact() {
// TODO Auto-generated method stub
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
while (cur.moveToNext()) {
try{
String lookupKey = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
System.out.println("The uri is " + uri.toString());
cr.delete(uri, null, null);
}
catch(Exception e)
{
//System.out.println(e.getStackTrace());
}
}
}
, wipeScreen 활동이 멈췄으므로 사용할 수 없습니다 ..이 서비스 시작을 도와주세요. wipeScreen 활동을 방해하지 않고 D .. 감사합니다 ..
덕분에 코드를 실행하는 IntentService를 사용할 수 있다고 생각 좋은 하루 .. :)) \ –
감사 Fredrik .. 그것은 멋지게 작동합니다. 좋은 하루 되세요 .. :) –