0

This code should restart my app:

Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(i);

but I get a massege getBaseContext() is undefined for the type ButtonView.PhoneCallListener how can I sove that without changing the extention's?

I tried getContext() instead but that got me to the main screen and not to the app.

Cœur
  • 37,241
  • 25
  • 195
  • 267
igor
  • 716
  • 1
  • 9
  • 27

1 Answers1

0

What you obviously need is the application's context. This can be obtained via the Context.getApplicationContext() method. And you can obtain a Context instance via View.getContext().

To put it in a nutshell, you can have access to application's context from the view code with:

getContext().getApplicationContext();

So this may work:

Context appContext = getContext().getApplicationContext();
Intent i = appContext .getPackageManager().getLaunchIntentForPackage(appContext .getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
getContext().startActivity(i);
sdabet
  • 18,360
  • 11
  • 89
  • 158
  • it's working ! I tried getApplicationContext(); and getContext() but did thout use them tugether thanks for the quick unswer man ! – igor Nov 15 '12 at 12:59
  • @igor: dont forget to mark it as answer. fiddler: Can you please provide some description about why ou have used getContext() and getApplicationContext() both. It would be helpfull. – Sahil Mahajan Mj Nov 15 '12 at 13:02
  • i write that: Intent i = getContext().getApplicationContext().getPackageManager() .getLaunchIntentForPackage(getContext().getApplicationContext().getPackageName()); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); getContext().startActivity(i); but i got steel to the main scean – igor Nov 15 '12 at 13:11