-3

I am trying to start a new activity from inside a service. I am using the following code, as many have suggested:

Intent i = new Intent(m_Context, myActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
m_Context.startActivity(i);

But, it gives an android.content.ActivityNotFoundException and says that I have to add the activity to my manifest. But the problem is that this is a service and has no manifest. Is there a way to start an activity without entering it in a manifest file?

ravindu1024
  • 1,496
  • 1
  • 13
  • 30
  • 2
    All activities must be declared in your manifest file, AndroidManifest.xml, using an element. – adneal Mar 19 '14 at 10:35
  • Try searching on Google before asking a question. This is the basic about Android and I believe there are alot of answers about this question. – osayilgan Mar 19 '14 at 10:41
  • @adneal: the issue is that this code is inside a .jar file which will be distributed. So What i really want to do is somehow start an activity from within a library. (compiled with an Android.mk and 'make' and without using Eclipse) – ravindu1024 Mar 19 '14 at 10:43
  • 1
    @osayilgan - i did search. everyone says that it cant be done without a manifest. please see my comment above. thanks. – ravindu1024 Mar 19 '14 at 10:45
  • @jack_black next time try to make the question more clear. I couldn't understand it clearly. – osayilgan Mar 19 '14 at 13:25

2 Answers2

3

If you want to distribute your code through a jar, you need to add the activity on the manifest in the app which will include the jar.

The only way to start an activity is to include it in a manifest.

Rino
  • 733
  • 8
  • 19
0

try this code it may help

Intent in=new Intent().setClass(MyAlarmService.this,Reminder.class);
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(in);
user3355820
  • 272
  • 1
  • 8