Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get my service to start an activity?
    primarykey
    data
    text
    <p>I have my service working, but for some reason it will not start my activity. It does not show an error in the logcat either. I want my service to start another activity. Is that possible? I checked to make sure my if statement was correct and it is. It does print out the HELLO. </p> <p>service code below:</p> <pre><code>package com.example.textsmslock; import java.util.Iterator; import java.util.List; import android.app.ActivityManager; import android.app.Service; import android.content.Intent; import android.content.pm.PackageManager; import android.os.IBinder; import android.util.Log; public class Logs extends Service { @Override public IBinder onBind(Intent arg0){ // TODO Auto-generated method stub return null; } @Override public void onStart(Intent intent, int startId) { // TODO Auto-generated method stub super.onStart(intent, startId); System.out.println("LOGS STARTED"); ActivityManager am = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE); List l = am.getRunningAppProcesses(); Iterator i = l.iterator(); PackageManager pm = this.getPackageManager(); while(i.hasNext()) { ActivityManager.RunningAppProcessInfo info = (ActivityManager.RunningAppProcessInfo)(i.next()); try { CharSequence c = pm.getApplicationLabel(pm.getApplicationInfo(info.processName, PackageManager.GET_META_DATA)); Log.w("LABEL", c.toString()); //System.out.println("this is the charsequence: " + c); //System.out.println("this is the log: " + Log.w("LABEL", c.toString())); if(c.equals("Messaging")) { System.out.println("HELLO \n"); startActivity(new intent(("com.example.textsmslock.Enable")); } } catch(Exception e) { //Name Not FOund Exception } } @Override public void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); System.out.println("LOGS STOPPED"); } } </code></pre> <p>android manifest</p> <pre><code>&lt;activity android:name=".Enable" android:label="@string/title_activity_enable" &gt; &lt;intent-filter&gt; &lt;action android:name="com.example.textsmslock.Enable" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;service android:name=".Logs" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/service&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload