F
F
Fotonick2016-02-09 20:13:41
Android
Fotonick, 2016-02-09 20:13:41

How to make an application autostart without it appearing?

I made an application and made it autostart after the phone boots up. Like this

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<receiver android:enabled="true" android:name=".BootUpReceiver"
            android:permission="android.permission.RECEIVE_BOOT_COMPLETED">

            <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
    </receiver>

public class BootUpReceiver extends BroadcastReceiver{

            @Override
            public void onReceive(Context context, Intent intent) {
                    Intent i = new Intent(context, MyActivity.class);  //MyActivity can be anything which you want to start on bootup...
                    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(i);  
            }

    }

But in general, I do not need the application to launch the activity on the screen after loading. All I need is for this activity to start doing its job (namely, to receive GPS coordinates and send them to the server, the application for drivers). How to do it? I have never seen an application that had the audacity to run in full screen after loading a smartphone, and I don’t want mine to behave like that.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2016-02-09
@gadfi

run not an activity but a service

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question