Skip to main content

Posts

Showing posts with the label calling

Using DialogFragments in Android

MainActivity.java : public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FragmentManager fm = getSupportFragmentManager(); dialogfragment testDialog = new dialogfragment(); testDialog.setRetainInstance(true); testDialog.show(fm, "fragment_name"); }} Dialogfragment.java : public class Dialogfragment extends DialogFragment { public void TestDialog() { // Empty constructor required for DialogFragment } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View view = inflater.inflate(R.layout.dialog, container); return view; } } dialog.xml : <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/edit_name" ...

Calling a Service from Activity in Android

This is a service class: public class serv extends Service { private static final String TAG = "MyService"; AlertDialog alertDialog @Override public IBinder onBind(Intent intent) { // TODO Auto-generated method stub return null; } public void onCreate() { Toast.makeText(getApplicationContext(), "My Service Created",Toast.LENGTH_LONG).show(); } @Override public void onDestroy() { Toast.makeText(this, "My Service Stopped",Toast.LENGTH_LONG).show(); Log.d(TAG, "onDestroy"); //player.stop(); } @Override public void onStart(Intent intent, int startid) { Toast.makeText(this, "My Service Started",Toast.LENGTH_LONG).show(); Log.d(TAG, "onStart"); //player.start(); } } Call service from activity: public class MainActivity ...