Jump to content

RESOLU: Démarrer une activity en background.


Profete162

Recommended Posts

Salut le monde!

J'ai réussi à faire pour mon appli, une préférence qui permet de la démarrer ou pas au démarrage.

Tout semble fonctionner pour le mieux avec le BroadcastReceiver!

Mais dans un souci de bien faire les choses, j'aimerais que mon appli tourne en fond et ne se lance pas! Je ne sais pas si je me fais bien comprendre, mais en gros, j'aimerais que l'appli soit lancée, mais que la fenêtre principale ne s'affiche pas.

J'ai pour l'instant ceci dans mon code:

public class MyStartupIntentReceiver extends BroadcastReceiver { 
   static SharedPreferences prefs;
    @Override 
    public void onReceive(Context context, Intent intent) { 


        if(prefStart){ 

            /* Create intent which will finally start the Main-Activity. */ 
            Intent myStarterIntent = new Intent(context, TaskOS .class); 
            /* Set the Launch-Flag to the Intent. */ 
            myStarterIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
            /* Send the Intent to the OS. */ 
            context.startActivity(myStarterIntent); 

        }

    } 
} 

Une idée pour arriver à mes fins?

merci d'avance.

Edited by Profete162
Link to comment
Share on other sites

Bah un service qui fait ça dans son onStart() me paraît pas si mal ou bien je n'ai rien compris. Sur l'appli que je développe, c'est le service qui initialise et utilise le NotificationManager et ça fonctionne très bien.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...