2014-01-24 157 views
-1

我開發一個應用程序,需要從用戶的任務數,並提醒他時間。如何讓我的應用程序在後臺運行

所以,我需要知道如何在後臺運行我的應用程序以及如何從SQLite獲取數據 - 日期&時間 - 設置鬧鐘。

類任務:

public class Task { 
String name; 
String discrb; 
int day , month , year ,donecheck ,periocheck,hour,minute; 
public Task() 
    { 
name=discrb=""; 
donecheck =day=month=year=periocheck =0;  
    } 
} 
+2

這個問題表明缺乏Android編程基礎知識。在做任何事之前,你應該通過官方教程。 –

回答

0

使用下面的代碼。

public class MainActivity extends Activity { 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     Intent intent = new Intent(MainActivity.this, AppService.class); 
     startService(intent); 

     hideApp(getApplicationContext().getPackageName()); 
     System.out.println("Inside of main"); 
    } 

    private void hideApp(String appPackage) { 
     ComponentName componentName = new ComponentName(appPackage, appPackage 
       + ".MainActivity"); 
     getPackageManager().setComponentEnabledSetting(componentName, 
       PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 
       PackageManager.DONT_KILL_APP); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     getMenuInflater().inflate(R.menu.main, menu); 
     return true; 
    } 
}