I am developing an app in which i want to launch any application installed on my device. I have tried the following code.
Button bClock = (Button) findViewById(R.id.button1);
String app="com.whatsapp";
bClock.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_MAIN);
PackageManager managerclock = getPackageManager();
i = managerclock.getLaunchIntentForPackage(app);
i.addCategory(Intent.CATEGORY_LAUNCHER);
startActivity(i);
}
});
It shows error:
Cannot refer to a non-final variable app inside an inner class defined in a different method
But if I directly use "com.whatsapp" instead of storing in String, it is working. Help me to solve this issue