I have this language settings on my app. After I set my desired language and restarting, the language didn't apply, rather setting back to the default language. Can anyone help me with this?
Here's my code
import java.util.Locale;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
public class AndroidLocalize extends Activity {
Spinner spinnerctrl;
Button btn;
Locale myLocale;
#
Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.androidlocalize);
spinnerctrl = (Spinner) findViewById(R.id.spinner1);
spinnerctrl.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView <? > parent, View view,
int pos, long id) {
if (pos == 1) {
Toast.makeText(parent.getContext(),
"You have selected Filipino", Toast.LENGTH_SHORT)
.show();
Intent nextForm = new Intent(".MainActivity");
startActivity(nextForm);
setLocale("tl");
} else if (pos == 2) {
Toast.makeText(parent.getContext(),
"You have selected English", Toast.LENGTH_SHORT)
.show();
Intent nextForm = new Intent(".MainActivity");
startActivity(nextForm);
setLocale("en");
}
}
public void onNothingSelected(AdapterView <? > arg0) {
// TODO Auto-generated method stub
}
});
}
public void setLocale(String lang) {
myLocale = new Locale(lang);
Resources res = getResources();
DisplayMetrics dm = res.getDisplayMetrics();
Configuration conf = res.getConfiguration();
conf.locale = myLocale;
res.updateConfiguration(conf, dm);
Intent refresh = new Intent(this, AndroidLocalize.class);
startActivity(refresh);
}
}
Thanks a lot!
when AndroidLocalize created, you should check for configuration, if exists then using that confguration start MainActivity.
what you are doing is after setting you are starting same activty again, since on create method you are not checking set config it will display the default one
solution,
1. check config oncreate
2. set locale first and then call startActivity
Related
I'm pretty new to Android Studio and Java overall so this might be simple question but I couldn't find any solutions or either couldn't use them to fix my issue.
So I have a RecyclerView which I can insert items from a list of pre-defined items with the function "addItems()" when I press to a button and display them.
Also those items have ImageButtons -which is just a transparent rectangle- to get individual clicks on them.
The purpose of these ImageButtons are to switch to a new activity which I defined in the "addItems()" method.
But the problem is, I can't catch -but they respond to the clicks- click on those items, and also I can't pass the activity class or the layout file.
To be exact, I want to use these buttons to switch to a new activity and display the info of that item there.
It's my first question here, so if I need to show any code, please tell me to.
NewsAdapter.java
package com.example.yiyecek2.Activities;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.yiyecek2.R;
import java.util.List;
public class NewsAdapter extends RecyclerView.Adapter<NewsAdapter.NewsViewHolder>
{
Context mContext;
List<NewsItem> mData;
public NewsAdapter(Context mContext, List<NewsItem> mData) {
this.mContext = mContext;
this.mData = mData;
}
#NonNull
#Override
public NewsViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
View layout;
layout = LayoutInflater.from(mContext).inflate(R.layout.lyt_restoran,viewGroup,false);
return new NewsViewHolder(layout);
}
// Changed below ----------
#Override
public void onBindViewHolder(#NonNull NewsViewHolder newsViewHolder, int position) {
// Bind data here
newsViewHolder.tvSellerName.setText(mData.get(position).getSellerName());
newsViewHolder.tvSellerAddress.setText(mData.get(position).getSellerAddress());
newsViewHolder.ivSellerImage.setImageResource(mData.get(position).getSellerImage());
newsViewHolder.tvMinCost.setText(mData.get(position).getMinCost());
newsViewHolder.tvMinTime.setText(mData.get(position).getMinTime());
newsViewHolder.tvDeliveryCost.setText(mData.get(position).getDeliveryCost());
newsViewHolder.tvClassToGo.setText(mData.get(position).getClassToGo());
// Line below is the buttons attached to the items which I aim to use on switching Activities
newsViewHolder.ibGoSellerPage.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View view) {
Intent intent = new Intent(SiparisActivity.this, classDominos.class);
startActivity(intent); // startActivity is marked red
}
});
}
// Changed above ----------
#Override
public int getItemCount() {
return mData.size();
}
public class NewsViewHolder extends RecyclerView.ViewHolder{
TextView tvSellerName, tvSellerAddress, tvMinCost, tvMinTime, tvDeliveryCost, tvClassToGo;
ImageView ivSellerImage;
ImageButton ibGoSellerPage;
public NewsViewHolder(#NonNull View itemView) {
super(itemView);
tvSellerName = itemView.findViewById(R.id.tvFoodName);
tvSellerAddress = itemView.findViewById(R.id.tvFoodDescription);
ivSellerImage = itemView.findViewById(R.id.ivFoodImage);
tvMinCost = itemView.findViewById(R.id.tvFoodCost);
tvMinTime = itemView.findViewById(R.id.tvMinTime);
tvDeliveryCost = itemView.findViewById(R.id.tvDeliveryCost);
tvClassToGo = itemView.findViewById(R.id.tvClassToGo);
ibGoSellerPage = itemView.findViewById(R.id.ibGoSellerPage);
//int position = getAdapterPosition();
//Toast.makeText(mContext.getApplicationContext(), "Position is: "+position, Toast.LENGTH_SHORT).show();
}
}
}
SiparisActivity.java //this is where I list restaurant items with ImageButtons said above.
package com.example.yiyecek2.Activities;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.yiyecek2.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
import recyclerview.CustomItemAnimator;
public class SiparisActivity extends AppCompatActivity {
Button btnListRestaurants;
RecyclerView NewsRecyclerView;
NewsAdapter newsAdapter;
List<NewsItem> mData;
ImageButton ibGoSellerPage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_siparis);
// Hide the action bar
getSupportActionBar().hide();
NewsRecyclerView = findViewById(R.id.news_rv);
btnListRestaurants = (Button) findViewById(R.id.buttonListRestaurants);
NewsRecyclerView.setLayoutManager(new LinearLayoutManager(this));
NewsRecyclerView.setHasFixedSize(true);
NewsRecyclerView.setItemAnimator(new CustomItemAnimator());
// Get clicks on the "List Restaurants"
btnListRestaurants.setOnClickListener(new View.OnClickListener() {
int restaurantCount = 0;
#Override
public void onClick(View view) {
Toast toast = Toast.makeText(getApplicationContext(), "Listing Restaurants", Toast.LENGTH_SHORT);
toast.show();
Timer timerToTransition;
timerToTransition = new Timer();
TimerTask task = new TimerTask() {
public void run() {
addItems();
restaurantCount++;
if (restaurantCount > 9)
{
System.out.println(restaurantCount);
timerToTransition.cancel(); // Stops the timer when theres 10 Restaurants listed
}
}
};
timerToTransition.scheduleAtFixedRate(task,0,300); // waits 300ms before creating a new Restaurant
}
});
if (ibGoSellerPage != null) // Check if Restaurant button exists
{
System.out.println("ON CLICK HERE");
ibGoSellerPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
System.out.println("ON CLICK HERE");
}
});
}
mData = new ArrayList<>();
// fill list news with pre defined data
// Adapter ini and setup
newsAdapter = new NewsAdapter(this,mData);
NewsRecyclerView.setAdapter(newsAdapter);
NewsRecyclerView.setLayoutManager(new LinearLayoutManager(this));
}
private void addItems()
{
RecyclerView.State state = null;
int switchInt = 0; // To use in the switch
// Random integer list to assign switchInt a random value
int[] intList;
intList = new int[]{0,1,2,3,4,5,6,7};
// Pick a random int
Random rand = new Random();
int rndInt = rand.nextInt(5);
// Check if the array's index isn't empty(-1)
while (intList[rndInt] != -1)
{
switchInt = (int) intList[rndInt];
intList[rndInt] = -1;
}
//System.out.println(rndInt);
switch(switchInt) {
case 0:
mData.add(0,new NewsItem("Domino's Pizza","Sarıgöl, Ordu Cd. No:128, 34240 Gaziosmanpaşa/İstanbul",
R.drawable.dominos,"32 TL","30 dk.","0 TL","classDominos")); // I'm trying to catch that "classDominos" to use to switch Activity
break;
case 1:
mData.add(0,new NewsItem("Migros","Bağlarbaşı, Küçükköy Yolu Cd., 34245 Gaziosmanpaşa/İstanbul",
R.drawable.migroslogo,"32 TL","25 dk.","0 TL", "classDominos"));
break;
case 2:
mData.add(0,new NewsItem("KFC","Yeşilpınar Mah. Şehit Metinkaya Sok Vialand AVM No:11 Mağaza No:237, 34065 Eyüpsultan",
R.drawable.kfclogo,"32 TL","35 dk.","3 TL", "classDominos"));
break;
case 3:
mData.add(0,new NewsItem("Popeyes","Yeşilpınar Mah. Şehit Metin Kaya Sok. No:11 K:3 Vialand AVM, 34065",
R.drawable.popeyeslogo,"32 TL","35 dk.","3 TL", "classDominos"));
break;
case 4:
mData.add(0,new NewsItem("Mado","İslambey, Hz. Halid Blv. No:43 D:B, 34050 Eyüpsultan/İstanbul",
R.drawable.madologo,"32 TL","35 dk.","3 TL", "classDominos"));
break;
default:
break;
}
System.out.println("Added item");
newsAdapter.notifyItemInserted(0);
NewsRecyclerView.getLayoutManager().smoothScrollToPosition(NewsRecyclerView, state, 0);
// Un-commenting the lines below crash the app when "Listing Restaurants" (Creating items)
//ibGoSellerPage = (ImageButton) findViewById(R.id.ibGoSellerPage);
/*ibGoSellerPage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
System.out.println("ON CLICK HERE");
}
});
*/
}
}
I can see the individual buttons in the profiler but how to catch clicks on them? (You can see I'm holding the button on the right)
Profiler Screenshot
I think the problem with you is that the click event happen on the screen in another view
By making a transparent rectangle i think the click go to the parent view
Try to test that for ex:
<LinearLayout
android:id="#+id/layout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
handle the click on layout view if it work so you need to change the transparent rectangle button to a bold one or another approach
better to add some code from your side to help us understand the problem well
So just to practice I've created a Pythagorean theorem calculator app. I want each answer that I obtain to be stored in another activity(a "history" page). I'm trying to use intents to send/receive the arraylist and items. I get the most recent one, but it is overwritten after each press of the button.
package com.example.hypnotenusecalculatorrebuild;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
//ToDo history button is broken. doesn't display listview when pressed.
public void toHistory(View view) {
// Intent intent = new Intent(getApplicationContext(), HistoryActivity.class);
//
// startActivity(intent);
}
public void findHypno(View view) {
Log.i("Info", "button pressed");
EditText editTextNumberA = (EditText) findViewById(R.id.editTextNumberA);
EditText editTextNumberB = (EditText) findViewById(R.id.editTextNumberB);
TextView textViewAnswer = (TextView) findViewById(R.id.textViewAnswer);
String message;
String cSquared;
if (editTextNumberA.getText().toString().isEmpty() || editTextNumberB.getText().toString().isEmpty()) {
message = "Please enter a number for each dimension";
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
} else {
Number numberA = new Number();
Number numberB = new Number();
Number numberC = new Number();
numberA.number = Double.parseDouble(editTextNumberA.getText().toString());
numberB.number = Double.parseDouble(editTextNumberB.getText().toString());
numberA.squareNumber();
numberB.squareNumber();
numberC.number = numberA.number + numberB.number;
numberC.squareRoot();
Log.i("test numberA", String.valueOf(numberA.number));
Log.i("test numberB", String.valueOf(numberB.number));
Log.i("test numberC", String.valueOf(numberC.number));
cSquared = Double.toString(numberC.number);
textViewAnswer.setText(cSquared);
ArrayList<String> historyList = new ArrayList<String>();
historyList.add("test");
Intent intent = new Intent(getApplicationContext(), HistoryActivity.class);
intent.putExtra("answer", cSquared);
intent.putStringArrayListExtra("arrayList", historyList);
startActivity(intent);
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
package com.example.hypnotenusecalculatorrebuild;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;
import java.util.function.ToDoubleBiFunction;
public class HistoryActivity extends AppCompatActivity {
public void back(View view) {
finish();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_history);
Intent getList = getIntent();
ArrayList<String> historyList = getList.getStringArrayListExtra("arrayList");
historyList.add(getList.getStringExtra("answer"));
ListView listViewHistory = (ListView) findViewById(R.id.listViewHistory);
ArrayAdapter historyListArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, historyList);
listViewHistory.setAdapter(historyListArrayAdapter);
// ToDo - intent isn't working as attended, only saves one item and gets overwritten each time
//Intent historyIntent = getIntent();
// get extra needs a name from put extra
// String testGetIntent = historyIntent.getStringExtra("answer");
// Log.i("testIntentString", testGetIntent);
// historyList.add(historyIntent.getStringExtra("answer"));
}
}
here is a different approach. make a public interface in a separate file named "extensions" or whatever and initialize your arraylist there like so:
public interface ext {
ArrayList<String> myArray = new ArrayList<String>();
}
this interface is created when the app runs and lives for as long as the app lives meaning you can always access and manipulate it anywhere in your app without worrying whether the activity is being killed or not. so you can add or remove elements to or from it wherever you want.
Access the array this way:
ext.myArray.add("new item")
I'm struggling with why this code won't compile, I'm trying to get the current wallpaper, then change it, then give the option to change it back.
Below is my code, it doesn't compile because it can't resolve symbol 'context' and it says my drawable cannot be converted to an integer which doesn't make any sense whatsoever.
I'm trying to change the drawable to a bitmap AND I have imported the import
android.content.Context
so what is it I am doing wrong here?? this is my code, the onClick stores the wallpaper and starts the change activity, the onPush method resets the wallpaper and exits the app, any help would be appreciated thanks!
import android.content.Context;
import android.app.Activity;
import android.app.WallpaperInfo;
import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import java.io.IOException;
import static android.app.WallpaperManager.*;
public class SetWallpaperActivity extends Activity {
public Drawable originalWallpaper;
public Bitmap paper1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View view) {
WallpaperManager wm = WallpaperManager.getInstance(this);
originalWallpaper = wm.getDrawable();
paper1 = BitmapFactory.decodeResource(context.getResources(),
originalWallpaper);
Intent intent = new Intent(
ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(EXTRA_LIVE_WALLPAPER_COMPONENT,
new ComponentName(this, MyWallpaperService.class));
startActivity(intent);
}
public void onPush(View view) {
WallpaperManager wm = WallpaperManager.getInstance(this);
WallpaperInfo wallpaperInfo = wm.getWallpaperInfo();
if (wallpaperInfo != null) {
try {
wm.setBitmap(paper1);
finish();
} catch (IOException e) {
e.printStackTrace();
}
}
finish();
System.exit(0);
}
}
This is the error code I'm getting:
'decodeResource(android.content.res.Resources, int)' in 'android.graphics.BitmapFactory' cannot be applied to '(android.content.res.Resources, android.graphics.drawable.Drawable)'
I'm very new to android. I want to create an application that turns off all sounds at the selected time. I created a service with some code and in Eclipse there's no errors, but when I press the button nothing happens. I can see in Application Manager that my program and the service SilentHours are running. Here's my code:
MainActivity.java
package com.example.silencecontrol;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
public final static String EXTRA_NAME = "sending silentHour value to service SilenceHours";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void setSilenceHours(View view) {
EditText editText1 = (EditText)findViewById(R.id.editText1);
TextView textView1 = (TextView)findViewById(R.id.textView1);
if(editText1.length() > 0) {
Intent intent = new Intent(this, SilentHours.class);
String editText1String = editText1.getText().toString();
int silentHour = Integer.parseInt(editText1String);
intent.putExtra(EXTRA_NAME, silentHour);
this.startService(intent);
} else {
textView1.setText("Please enter the silence hour. ");
}
}
}
SilentHours.java
package com.example.silencecontrol;
import java.util.Calendar;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.IBinder;
public class SilentHours extends Service {
public SilentHours() {
}
protected void onHandleIntent(Intent intent) {
int silentHour = Integer.parseInt(intent.getStringExtra(MainActivity.EXTRA_NAME));
Calendar calendar = Calendar.getInstance();
int currentTime = calendar.get(Calendar.HOUR_OF_DAY);
if(currentTime >= silentHour) {
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
}
}
#Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}
And by the way I can't #Override the onHandleIntent method. If I put the #Override annotation I get error:
The method onHandleIntent(Intent) of type SilentHours must override or implement a supertype method.
Is that annotation necessary?
The method you are looking for is named onStartCommand, not onHandleIntent.
And no, it's not necessary to add this annotation to an overriden method, it's just a very good practice as you can get sure that you respected the signature of the super class.
Let you IDE help you when you code. Simply type "on" then ask for completion to see which method you can override.
Ok, thanks to below dude biggest issue is fixed. But whatever I print out, none is printed and I cannot print out the message what is typed in class 2 (nimekysija) as well :(. I really need that it stores name and in future it will write down name every time! Thanks for your help!
Problem must be in 2nd class tho. When I update editor.putString("nimi2", nimiS); nimiS into "plapla", then plapla actually shows up :/. So I have really no idea, what is problem!
(updated below classes too to the newest)
Class 1:
package viimane.voimalus;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.widget.TextView;
public class MainStuff extends Activity {
TextView tere;
String nimi;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
tere = (TextView) findViewById(R.id.tvTere);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean nimiOlemas = preferences.getBoolean("nimionolemas", false);
if (nimiOlemas == false){
startActivity(new Intent("viimane.voimalus.NIMEKYSIJA"));
finish();
}
if (nimiOlemas == true){
nimi = preferences.getString("nimi2", "");
System.out.print("töötab!");
tere.setText("Tere " + nimi);
}
System.out.print("töötab2!");
}
}
CLASS 2
package viimane.voimalus;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class nimekysija extends Activity {
EditText nimi;
SharedPreferences preferences;
String nimiS;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.nimekysija);
preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
nimi = (EditText) findViewById(R.id.etNimekysija);
nimiS = nimi.getText().toString();
Button kysOk = (Button) findViewById(R.id.bNimekysija);
kysOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
SharedPreferences.Editor editor = preferences.edit();
editor.putString("nimi2", nimiS); // nime kirjutamine
editor.putBoolean("nimionolemas", true); // nimi on kirjutatud!
editor.commit();
startActivity(new Intent("viimane.voimalus.MAINSTUFF"));
finish();
}
});
}
}
Ok I'm guessing you may be new to Java, forgive me if I'm incorrect. You never READ from nimiOlemas.
boolean nimiOlemas = preferences.getBoolean("nimionolemas", false);
nimiOlemas = false;
startActivity(new Intent("viimane.voimalus.NIMEKYSIJA"));
finish();
nimiOlemas = true;
I think what you are trying to do is initialize nimiOlemas and then, if it is false, start an activity, call finish, then set nimiOlemas to true, but this is not what you are doing. Is this what you want?
boolean nimiOlemas = preferences.getBoolean("nimionolemas", false);
if (nimiOlemas == false)
{
startActivity(new Intent("viimane.voimalus.NIMEKYSIJA"));
finish();
nimiOlemas = true;
}
= is an assignment, == is a boolean comparison. You say in your question that you check the value of your boolean, but you never do, you only assign to it.
Assuming that nimiOlemas is inherited from activity and not used in the activity class, or other supper class, then yes it is not used in nimekysija (Class 2). It IS used in class 1. But this should just be a warning... You will get this warning for every class that extends activity and doesn't use nimiOlemas.