μΆμ²:
https://stackoverflow.com/questions/46716069/how-to-make-background-process-in-android-studio
How To Make Background Process in Android Studio
hi guys thank you for answering my question,i have made an android app in android studio i want to make funtion when i close the app the function start automatically in background is there any way ...
stackoverflow.com
[μ‘ν°λΉν°]
public class App extends Application {
private static App instance;
private static Context context;
@Override
public void onCreate() {
super.onCreate();
App.context = getApplicationContext();
startService(new Intent(this, YourBackgroundService.class));
}
}
[ν΄λμ€]
public class YourBackgroundService extends Service {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
}
[AndroidManifest.xml]
<service android:name=".YourBackgroundService" />
μ°Έκ³ 2)
public class YourBackgroundService extends Service {
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
super.onCreate();
ServerThread thread = new ServerThread();
thread.start();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
}
class ServerThread extends Thread {
...
}
}
ꡬννκ³ μ νλ λ°±κ·ΈλΌμ΄λ κΈ°λ₯λ€μ onCreate ν΄λμ€μ μ μ΄μ£Όλ©΄ λλ€.
β» λ¨ Toast λ¬Έμ κ°μ Viewμ λ³νκ° μκΈ°λ κΈ°λ₯μ μ€λ₯κ° μκΈ΄λ€.
μΆμ²:
μμΌ (Socket) - 3. μμΌ μ¬μ©νκΈ° (2)
1. μ€ν κ²°κ³Ό νλ©΄ 2. ꡬν - SocketServer μμ€ν 리μμ€κ° μ μΌλ©΄ μμ€ν μ΄ μ‘ν°λΉν°λ₯Ό κ°μ λ‘ μ’ λ£μν¬ μ μλ€. μ΄λ κ² λλ©΄ μλ²κ° μ’ λ£κ° λκΈ° λλ¬Έμ μλ²λ₯Ό μ‘ν°λΉν°κ° μλ μλΉμ€λ‘
qlyh8.tistory.com