Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- MainService.get(this);
- }
- }
- public class MainService extends Service {
- public static Object sWait = new Object();
- public static MainService instance;
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- public static MainService get(Context mContext) {
- if (instance == null) {
- Intent intent = new Intent(mContext, MainService.class);
- mContext.startService(intent);
- }
- while (true) {
- if (instance != null) {
- Log.v("myLogs", "all is good!");
- break;
- }
- synchronized (sWait) {
- try {
- sWait.wait();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- return instance;
- }
- @Override
- public void onCreate() {
- Log.v("myLogs", "created!");
- instance = this;
- synchronized (sWait) {
- sWait.notify();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement