my program is not working ,
i have some kind of a problem with the surfaceviewexample class.
Unable to start activity java.lang.NullPointerException.
i am trying to push on the tut5 button which i made to start my surfaceview.
what is the reason for it ?
what am i doing wrong ?
SurfaceViewExample.java
public class SurfaceViewExample extends Activity implements View.OnTouchListener{
OurView v;
Bitmap ball;
float x,y;
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
v=new OurView(this);
v=setOnTouchListener(this);
ball= BitmapFactory.decodeResource(getResources(),R.drawable.ball);
x=y=0;
setContentView(v);
}
private OurView setOnTouchListener(SurfaceViewExample surfaceViewExample) {
return null;
}
#Override
protected void onPause(){
super.onPause();
v.pause();
}
#Override
protected void onResume(){
super.onResume();
v.resume();
}
#Override
public boolean onTouch(View v , MotionEvent me) {
return false;
}
public class OurView extends SurfaceView implements Runnable {
Thread t=null;
SurfaceHolder holder;
boolean isItOK=false;
public OurView(Context context){
super(context);
holder=getHolder();
}
#Override
public void run()
{
while (isItOK==true)
{
if(!holder.getSurface().isValid()){
continue;
}
Canvas c=holder.lockCanvas();
c.drawARGB(255,150,150,10);
c.drawBitmap(ball,x,y,null);
holder.unlockCanvasAndPost(c);
}
}
public void pause(){
isItOK=false;
while(true){
try{
t.join();
}catch (InterruptedException e){
e.printStackTrace();
}
break;
}
t=null;
}
public void resume(){
isItOK=true;
t=new Thread(this);
t.start();
}
}
}
menu.java
public class menu extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView (com.example.youtubeproject.R.layout.activity_main);
final MediaPlayer buttonSound = MediaPlayer.create(menu.this,
com.example.youtubeproject.R.raw.button_click);
Button tut1= (Button)findViewById(com.example.youtubeproject.R.id.tutorial1);
Button tut2= (Button)findViewById(com.example.youtubeproject.R.id.tutorial2);
Button tut3= (Button)findViewById(com.example.youtubeproject.R.id.tutorial3);
Button tut4=(Button)findViewById(com.example.youtubeproject.R.id.tutorial4);
Button tut5=(Button)findViewById(com.example.youtubeproject.R.id.tutorial5);
tut1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonSound.start();
setContentView (com.example.youtubeproject.R.layout.tutorial1);
Intent TutorialIntent=new Intent("com.example.youtubeproject.TUTORIAL1");
startActivity(TutorialIntent);
//startActivity(new Intent("com.example.youtubeproject.TUTORIAL1"));
}
});
tut2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonSound.start();
startActivity(new Intent("com.example.youtubeproject.TUTORIALTWO"));
}
});
tut3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonSound.start();
setContentView (com.example.youtubeproject.R.layout.wallpapaer);
Intent TutorialIntent=new
Intent("com.example.youtubeproject.TUTORIALTHREE");
startActivity(TutorialIntent);
}
});
tut4.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonSound.start();
Intent TutorialIntent=new
Intent("com.example.youtubeproject.TUTORIALFOUR");
startActivity(TutorialIntent);
//setContentView (com.example.youtubeproject.R.layout.wallpapaer);
//Intent TutorialIntent=new
Intent("com.example.youtubeproject.TUTORIALTHREE");
//startActivity(TutorialIntent);
}
});
tut5.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
buttonSound.start();
//startActivity(new Intent("com.example.youtubeproject.TUTORIALFIVE"));
Intent TutorialIntent=new
Intent("com.example.youtubeproject.TUTORIALFIVE");
startActivity(TutorialIntent);
//setContentView (com.example.youtubeproject.R.layout.wallpapaer);
//Intent TutorialIntent=new
Intent("com.example.youtubeproject.TUTORIALTHREE");
//startActivity(TutorialIntent);
}
});
}
public boolean onCreateOptionsMenu(Menu menu)
{
super.onCreateOptionsMenu(menu);
MenuInflater awesome=getMenuInflater();
awesome.inflate(com.example.youtubeproject.R.menu.main_menu,menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item){
switch(item .getItemId()){
case com.example.youtubeproject.R.id.menuSweet:
startActivity(new Intent("com.example.youtubeproject.SWEET"));
return true;
case com.example.youtubeproject.R.id.menuToast:
Toast andEggs=Toast.makeText(menu.this,"this is a toast
",Toast.LENGTH_LONG);
andEggs.show();
return true;
}
return false;
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.youtubeproject"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.youtubeproject.MENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Tutorial1"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.youtubeproject.TUTORIAL1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutoralTwo"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.youtubeproject.TUTORIALTWO" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialThree"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.youtubeproject.TUTORIALTHREE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".SurfaceViewExample"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.youtubeproject.TUTORIALFIVE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TutorialFour"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.youtubeproject.TUTORIALFOUR" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Sweet"
android:label="#string/app_name"
android:theme="#android:style/Theme.Dialog" >
<intent-filter>
<action android:name="com.example.youtubeproject.SWEET" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Declare you SurfaceViewExample activity into Menifest like that;
<activity
android:name="com.example.youtubeproject.SurfaceViewExample" >
</activity>
Related
I can't find my mistakes......
while studying social login(google, facebook), almost don't know what to do...
I tried my best, but couldn't find errors.
When I connect my android devices and run on them, my devices get jammed.
So I should force terminate my app.
here is my code
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.acepeter.smartcalendar">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
tools:replace="android:supportsRtl">
<activity android:name=".SignupActivity"/>
<activity android:name=".MainActivity"/>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BaseActivity" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id"
tools:replace="android:value" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<activity android:name=".LoginActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="#string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
</manifest>
splashactivity.java
public class SplashActivity extends AppCompatActivity {
/*
앱이 맨처음 실행하면 띄어지는 로딩 화면
앱에서 필요한 네트워크 연결, 데이터베이스 연결
설정 값 적용 등의 앱에서 처음에 해야할 기능을 수행하기 위한 화면
앱 또는 서버 점검 알림창을 띄우는 화면
Remote Config(원격 구성)
서버에서 앱의 대한 설정을 해줄 수 있습니다.
설정 : 사용자가 사용하는 설정이 아닌 앱 관리자가 모든 앱의 설정을
관리하기 위한 기능
*/
FirebaseRemoteConfig remoteConfig;
LinearLayout container;
// #Override
// protected void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_logo);
// startLoading();
// mAuth = FirebaseAuth.getInstance();
// }
// private void startLoading() {
// Handler handler = new Handler();
// handler.postDelayed(new Runnable() {
// #Override
// public void run() {
// finish();
// }
// }, 2000);
//}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_logo);
container = findViewById(R.id.splash_layout_container);
// 전체 화면
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
startLoading();
remoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(100)
.build();
remoteConfig.setConfigSettingsAsync(configSettings);
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
remoteConfig.fetchAndActivate()
.addOnCompleteListener(new OnCompleteListener<Boolean>() {
#Override
public void onComplete(#NonNull Task<Boolean> task) {
if (task.isSuccessful()) {
Log.i("RemoteConfig", "Remote Success");
} else {
Log.i("RemoteConfig", "Remote Failed");
}
displayMessage();
}
});
}
private void displayMessage() {
// 서버에 저장된 설정 값을 가져오도록 함.
String background = remoteConfig.getString(getString(R.string.theme_color));
boolean caps = remoteConfig.getBoolean("splash_message_caps");
String message = remoteConfig.getString("splash_message");
container.setBackgroundColor(Color.parseColor(background));
if(caps) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setPositiveButton("확인", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.create().show();
}else {
// 다음 화면으로 넘어감
Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(intent);
finish();
}
}
private void startLoading() {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
#Override
public void run() {
finish();
}
}, 2000);
}
}
MAINMENU.CLASS
public class MainMenu extends Activity {
ImageButton playButton;
ImageButton soundButton;
SoundPlayers soundPlayers;
MediaPlayer firstMenusMusic;
MediaPlayer arenaMusic;
MediaPlayer buttonSound;
boolean now_sound;
OthersIO othersIO;
//MediaPlayer firstMenusMusic;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_menu);
playButton = (ImageButton) findViewById(R.id.play_button);
soundButton = (ImageButton) findViewById(R.id.sfx_sound);
playButtonEvent();
}
private void playButtonEvent() {
playButton.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(MainMenu.this, UserConfig.class);
MainMenu.this.finish();
startActivity(intent);
}
});
}
}
USERCONFIG.CLASS
public class UserConfig extends Activity {
ImageButton userConfigBack;
ImageButton userConfigOK;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_config);
....
}
public void chooseCharacter() {
....
}
public void back() {
userConfigBack.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(UserConfig.this, MainMenu.class);
UserConfig.this.finish();
startActivity(intent);
}
});
}
public void OK() {
userConfigOK.setOnClickListener( new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(UserConfig.this, EnemyConfig1.class);
UserConfig.this.finish();
createPlayerData();
startActivity(intent);
}
});
}
public void createPlayerData() {
....
}
}
This is the Android Manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ulartangga"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.ulartangga.MainMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".UserConfig"
android:parentActivityName=".MainMenu" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainMenu" />
</activity>
<activity
android:name=".EnemyConfig1"
android:parentActivityName=".UserConfig"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".UserConfig" />
</activity>
<activity
android:name=".EnemyConfig2"
android:parentActivityName=".EnemyConfig1"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".EnemyConfig1" />
</activity>
<activity
android:name=".Arena"
android:parentActivityName=".EnemyConfig1"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".EnemyConfig1" />
</activity>
</application>
</manifest>
My problem is...
when I click play button on view from mainmenu.class. I can go to another page(go to view from userconfig.class). but when I click OK button in view from userconfig.class, I can't go to another page.
in USERCONFIG.CLASS change it to
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_config);
OK();
back();
}
call UserConfig.this.finish(); after startActivity()
Manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name="com.teamandy.MainActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:theme="#*android:style/Theme.Black.NoTitleBar" android:name="com.teamandy.Choosetype" android:screenOrientation="portrait" />
<activity android:theme="#*android:style/Theme.Black.NoTitleBar" android:name="com.teamandy.frames1" android:screenOrientation="portrait" />
</application>
Main Activity:
this.startb=(Button)findViewById(R.id.btn_start);
this.startb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent strtint=new Intent(MainActivity.this, Choosetype.class);
//strtint.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
strtint.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
strtint.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
strtint.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(strtint);
finish();
}
});
Choosetype Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.choosefrm);
}
public void f1(View v ){
Choosetype.number=1;
this.mcontexts=this;
startActivity();
}
public void f2(View v){
Choosetype.number=2;
this.mcontexts=this;
startActivity();
.........................unti f20 etc. used
I have a ListActivity as the main activity of my app. Items in the list should be searchable but naturally I don't want to start the same activity over and over, hence singleTop. However, I do want the user to be able to return to the main list after a search and that's causing me some trouble. Currently, pressing back after a search will terminate the app. One solution is to make a copy of the list activity specifically to handle searching but I can't imagine that's the best way to go about it. I have briefly tried activity-alias but every permutation I have tried either doesn't change the behaviour or performs a Web search instead. I don't know if activity-alias is even appropriate but I've included an example anyway.
My question is, is there a best way to achieve what I'm trying to do that doesn't involve superfluous code maintenance?
<activity
android:name=".MainListActivity"
android:label="#string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias
android:name=".SearchList"
android:targetActivity=".MainListActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity-alias>
I found an embarrassingly simple solution.
Manifest:
<activity
android:name=".MainListActivity"
android:label="#string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable" />
</activity>
List/search activity:
public class MainListActivity extends FragmentActivity
implements LoaderManager.LoaderCallbacks<Cursor>
{
private boolean searching = false;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_cheapest);
dbHelper = new DatabaseHelper(this);
String[] fromColumns = {"pname", "store", "unit_price"};
int[] toViews =
{R.id.entryProductName, R.id.entryStore, R.id.entryUnitPrice};
adapter = new SimpleCursorAdapter(this, R.layout.cheapest_row_entry,
null, fromColumns, toViews);
ListView lv = (ListView)findViewById(android.R.id.list);
lv.setAdapter(adapter);
lv.setEmptyView(findViewById(android.R.id.empty));
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> l, View v, int position,
long id) {
searching = false;
startActivity(new Intent(getBaseContext(),
EditProductActivity.class).putExtra("pid", ""+id));
}
});
handleIntent(getIntent());
}
#Override
public void onBackPressed() {
if (searching) {
searching = false;
getSupportLoaderManager().restartLoader(LOADER_MAIN, null, this);
} else {
finish();
}
}
#Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
searching = true;
filter = intent.getStringExtra(SearchManager.QUERY);
getSupportLoaderManager().restartLoader(LOADER_SEARCH, null, this);
} else {
getSupportLoaderManager().initLoader(LOADER_MAIN, null, this);
}
}
...
}
However, I did first get activity-alias working. I'm including it for posterity.
Manifest:
<activity
android:name=".MainListActivity"
android:label="#string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="android.app.default_searchable"
android:value=".SearchListActivity" />
</activity>
<activity-alias
android:name=".SearchListActivity"
android:launchMode="singleTop"
android:targetActivity=".MainListActivity" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="#xml/searchable"
android:value=".SearchListActivity" />
</activity-alias>
List/search activity:
public class MainListActivity extends FragmentActivity
implements LoaderManager.LoaderCallbacks<Cursor>
{
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view);
...
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> l, View v, int position,
long id) {
if (Intent.ACTION_SEARCH.equals(getIntent().getAction())) {
finish();
}
startActivity(new Intent(getBaseContext(),
EditProductActivity.class).putExtra("pid", ""+id));
}
});
handleIntent(getIntent());
}
#Override
protected void onNewIntent(Intent intent) {
handleIntent(intent);
}
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
filter = intent.getStringExtra(SearchManager.QUERY);
getSupportLoaderManager().restartLoader(LOADER_SEARCH, null, this);
} else {
getSupportLoaderManager().initLoader(LOADER_MAIN, null, this);
}
}
...
}
i have problem with sending Broadcast receive from one activity to other ..its not working my code is below..pls refer to it ..
sending class is:
public class SendBroadcast extends Activity {
public static String BROADCAST_ACTION = "com.unitedcoders.android.broadcasttest.SHOWTOAST";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
sendBroadcast();
}
});
}
public void sendBroadcast(){
Intent broadcast = new Intent();
broadcast.setAction("com.unitedcoders.android.broadcasttest.SHOWTOAST");
sendBroadcast(broadcast);
}
}
and reciving class is :
public class ToastDisplay extends Activity {
private BroadcastReceiver receiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
Log.i("asdasd","sdasdasd");
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "%%%%%%%%%%%%received", Toast.LENGTH_SHORT).show();
}
};
#Override
protected void onResume() {
IntentFilter filter = new IntentFilter();
filter.addAction(SendBroadcast.BROADCAST_ACTION);
registerReceiver(receiver, filter);
super.onResume();
}
#Override
protected void onPause() {
unregisterReceiver(receiver);
super.onPause();
}
}
Manifest file is ::::
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unitedcoders.android.broadcasttest"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".SendBroadcast"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ToastDisplay">
<intent-filter>
<action android:name="com.unitedcoders.android.broadcasttest.SHOWTOAST"> </action>
</intent-filter>
</activity>
</application>
</manifest>
you have not registered your Receiver in Manifest :registered as
<receiver android:name="receiver">
<intent-filter>
<action
android:name="com.unitedcoders.android.broadcasttest.SHOWTOAST"/>
</intent-filter>
</receiver>