1
I am creating an application using Bluetooth, where the method that receives the messages is static
.
Depending on the message the device receives, I’d like the app to do something other than simply show the message in a textView
(also static
) on the screen, such as calling another screen (setContentView
), create a Intent
any or present a AlertDialog.Builder
.
The problem is when a method static
tries to use these resources. I tried through this method static
create a class object ActivityMain
to use any other method that performed this process, however, errors also occur.
What to do?
It seems to me that its architecture contains serious structural problems.
View
static is a bad sign. Manually create objects of typeActivity
(instead of ordering from the system through thestartActivity
) is a lousy signal. I think we will need more details about your current architecture to better understand what to suggest.– Pablo Almeida
Good! I will try to present the problem in a simpler way. We have the main class:
– Willie Campos
We have a STATIC method being started public class Mainactivity extends Actionbaractivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // I’ll call a method Static start(); }}
– Willie Campos
private Static void inicio() { // None of the attempts compile... setContentView(R.layout.activity_main); Alertdialog.Builder Builder = new Alertdialog.Builder(this); Builder.setTitle("title"); Builder.setPositiveButton("OK",null); &#xTo; Intent Intent = new Intent(Mainactivity.this, otherActivity.class); // An option would be... // Instantiate an object in that class to use a NONSTATIC Mainactivity mainActivity = new Mainactivity(); mainActivity.call; }
– Willie Campos
private void nameOutraTela(){ // Here all above attempts compile... however also NAÕ WORKS // The App hangs when running }
– Willie Campos